0
我正在嘗試處理來自我的有效內容的更多信息。這是我如何設置推送通知的iPhone和消息來通過,這是我如何創建我的有效載荷:在應用中推送有效負載信息
// Create the payload body
$body['aps'] = array(
'alert' => $message,
'sound' => 'default',
'link_url' => $url,
);
在這是我的應用程序裏面。
// WHEN a push notification comes in
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable: Any]){
if let aps = userInfo["aps"] as? NSDictionary {
if let alert = aps["alert"] as? NSDictionary {
if (alert["message"] as? NSString) != nil {
//Do stuff
self.window = UIWindow(frame: UIScreen.main.bounds)
let storyboard = UIStoryboard(name: "Main", bundle: nil)
// redirect to section
var initialViewController = storyboard.instantiateViewController(withIdentifier: "ViewBookings")
self.window?.rootViewController = initialViewController
self.window?.makeKeyAndVisible()
}
} else if (aps["alert"] as? NSString) != nil {
self.window = UIWindow(frame: UIScreen.main.bounds)
let storyboard = UIStoryboard(name: "Main", bundle: nil)
// redirect to section
var initialViewController2 = storyboard.instantiateViewController(withIdentifier: "ViewBookings")
self.window?.rootViewController = initialViewController2
self.window?.makeKeyAndVisible()
}
}
}
但現在我需要閱讀link_url,因此我的應用可以重定向到不同的部分或推薦外部鏈接。 (它並不總是一個url) 我試過了:讓my_url = aps [「link_url」]爲? NSDictionary,然後描述爲字符串,但我什麼也得不到。
是你的APS [「LINK_URL」]一本字典或字符串? –