我已经使用这些函数在 AppDelegate 中处理了我的通知:
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable: Any])
和:
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable: Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void)
但我在点击通知时得到了不同的 react 。例如,当我有一个深层链接时,它在应用程序处于后台或前台时工作正常,但当应用程序关闭时,深层链接将不起作用。 我是 IOS 的新手,如果我的问题很基础,抱歉。
最佳答案
当应用程序关闭并且您按下推送通知时,不会调用推送通知接收消息。相反,application:didFinishLaunchingWithOptions:方法被调用(正如它应该的那样)。
诀窍是检查 launchOptions
字典中的通知。
if let remoteNotificationInfo = launchOptions?[.remoteNotification] as? [AnyHashable : Any] {
dealWithRemoteNotification(remoteNotificationInfo)
}
func dealWithRemoteNotification(_ userInfo:[AnyHashable : Any]) {
}
关于ios - 应用关闭时推送通知的行为不同,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50198440/