我试图从我的有效负载中处理更多信息。这就是我为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"]为? NSDictionary然后描述为字符串,但我什么都没得到。
答案 0 :(得分:0)
这取决于如何定义$ message和$ url对象。如果它们是字符串,则以下内容应该有效:
const getInfo = R.flip(R.reduce(R.flip(R.chain)))
从您的代码看起来您的对象如下所示:
if let my_url = aps["link_url"] as? String {
print(my_url)
}