【发布时间】:2016-11-27 10:48:55
【问题描述】:
我正在使用 Firebase 通知来发送和接收 RemoteNotification。
当我收到通知时,我还会收到一个 ID,让我可以识别特定的“帖子”。
现在,当我点击通知时,我需要该应用打开一个 viewController 并传递接收到的 ID,以便启动一个加载“发布”信息的方法(在 viewDidLoad() 中)。
这是通知的代码:
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable: Any],
fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
// Print message ID.
print("Message ID: \(userInfo["gcm.message_id"]!)")
let aps = userInfo["aps"] as! NSDictionary
let body_notifica = aps["alert"]! as! NSDictionary
let titolo_notifica = body_notifica["title"]! as! String
let testo_notifica = body_notifica["body"]! as! String
let id_lavoro = userInfo["id_lavoro"]! //THIS IS THE ID I NEED TO PASS TO VIEW CONTROLLER
if application.applicationState == UIApplicationState.inactive || application.applicationState == UIApplicationState.background{
let viewController = self.window!.rootViewController!.storyboard!.instantiateViewController(withIdentifier: "annuncio_view_controler")
viewController.performSegue(withIdentifier: "a", sender: <#T##Any?#>)
}
let banner = Banner(title: titolo_notifica, subtitle: testo_notifica, image: UIImage(named: "Info"), backgroundColor: UIColor(red:0.0/255.0, green:0.0/255.0, blue:0.0/255.0, alpha:0.5))
banner.dismissesOnTap = true
banner.show(duration: 3.0)
print(userInfo)
}
谢谢你们!
【问题讨论】:
标签: ios swift firebase push-notification firebase-cloud-messaging