ios - 推送通知在 UIApplication LaunchOptions RemoteNotificationKey 中不起作用

标签 ios swift push-notification

因为我更新了我的 AppDelegate 类中的所有 Notification 方法。 PushNotification 在应用打开和关闭模式时接收。当我的应用程序关闭并收到通知并尝试点击通知时,我遇到了这个问题,它打开了应用程序屏幕,但是这些代码行没有被调用:

let remoteNotification: NSDictionary! = launchOptions?[UIApplicationLaunchOptionsRemoteNotificationKey] as? NSDictionary
        print("remoteNotification = \(remoteNotification)")
        if (remoteNotification != nil) {
            print("***************************************\n\n\n\n\n launchOptions = \(launchOptions)\n ***************************************\n\n\n\n\n")

         self.notificationHandlingFunction(remoteNotification)
        }

当我想查看日志时,它不会出现在 Log 列表中:

enter image description here

我的设备连接了 Xcode 但没有运行。 在代码中我打印 RemoteNotification 但是当我搜索这个关键字时它没有显示。 我在 Swift 中遇到了这个问题。

出现这种情况时,如何管理我的Notification 方法。

最佳答案

转到项目>功能,打开后台模式并启用远程通知

enter image description here

然后在 app delegates 中简单地添加以下方法

func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject], fetchCompletionHandler completionHandler: (UIBackgroundFetchResult) -> Void) {
        self.notificationHandlingFunction(remoteNotification)
}

适用于所有情况

关于ios - 推送通知在 UIApplication LaunchOptions RemoteNotificationKey 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39912802/

相关文章:

ios - 在tableview中异步设置图像

iOS 9 方向自动旋转动画不起作用,但始终在主线程上

swift - 如何在 Swift 中正确获取作用域外的值 Do-Catch(使用 Try)

swift - 将 URL 数组转换为 UIImage 数组

ios - 尽管我收到通知,但 Didreceivenotification 从未被调用

react-native - React Native Android后台处理程序中重复的fcm推送通知

iphone - 我的 iOS 应用程序是否使用加密?

iOS 恢复 HLS 下载并删除部分下载的文件

ios - 如何在 swift 中将贴纸 View 添加到浏览器 View ?

objective-c - 关闭推送通知横幅