Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/96.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/opencv/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 应用未运行/应用终止时如何处理推送通知_Ios_Swift_Push Notification - Fatal编程技术网

Ios 应用未运行/应用终止时如何处理推送通知

Ios 应用未运行/应用终止时如何处理推送通知,ios,swift,push-notification,Ios,Swift,Push Notification,我正在使用firebase通知。当应用程序状态为后台时,它工作正常。但当应用程序未运行/终止时,不会调用func getPushNotiData(u通知:NSNotification) 在appDelegate文件中实现NotificationCenter以在dashView中处理通知 func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any]

我正在使用firebase通知。当应用程序状态为后台时,它工作正常。但当应用程序未运行/终止时,不会调用func getPushNotiData(u通知:NSNotification)

在appDelegate文件中实现NotificationCenter以在dashView中处理通知

func application(_ application: UIApplication, didReceiveRemoteNotification 
userInfo: [AnyHashable : Any]) {
NotificationCenter.default.post(name: NSNotification.Name(rawValue: 
"getPushNotificationData"), object: nil, userInfo: userInfo)
}
如果应用程序未运行/终止,则在didFinishLaunchingWithOptions委托方法中实现NotificationCenter

 if (launchOptions != nil)
    {
        let userInfo = launchOptions![.remoteNotification] as? [AnyHashable: Any]
        if userInfo != nil {
        NotificationCenter.default.post(name: NSNotification.Name(rawValue: "getPushNotificationData"), object: nil, userInfo: userInfo)
        }
    }
在dashView中处理NotificationCenter

override func viewDidAppear(_ animated: Bool) {
    NotificationCenter.default.addObserver(self, selector: #selector(self.getPushNotiData(_:)), name: NSNotification.Name(rawValue: "getPushNotificationData"), object: nil)
}

@objc func getPushNotiData(_ notification: NSNotification){
    if let url = notification.userInfo!["url"] as? String {
        let destination = storyboard?.instantiateViewController(withIdentifier: "NotificationDlsViewController") as! NotificationDlsViewController
        destination.notiUrl = url
        self.navigationController?.pushViewController(destination, animated: true)
}
}

如果应用程序未运行(已终止状态),则无法执行任何方法或代码,只有当用户单击推送通知时,您才能在
didfinitishlaunchingwithoptions
launchingOptions中接收推送通知的对象并对其进行处理……

当您在
didfinitishlaunchingwithoptions
中选中
launchingwithoptions
时,您的视图控制器可能尚未加载,因此
viewdid出现未调用,并且未在通知中心注册ViewController。当应用程序从通知启动时,尝试放入一些打印语句并检查调用顺序。

当应用程序未运行/终止/处于终止状态时,推送通知到达时,将不会执行任何方法。系统将只显示一个通知弹出窗口。@当应用程序未运行时,objc func getPushNotiData(Notification:NSNotification)方法未执行