【发布时间】:2016-12-15 18:09:13
【问题描述】:
我正在尝试从我的有效负载中处理更多信息。这就是我为 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,以便我的应用可以重定向到不同的部分或推荐外部链接。 (它并不总是一个网址) 我试过:让 my_url = aps["link_url"] as? NSDictionary 然后描述为字符串,但我什么也没得到。
【问题讨论】:
-
你的 aps["link_url"] 是字典还是字符串?
标签: iphone swift xcode push-notification