应用关闭时推送通知的行为不同
Push Notification acts different when app is closed
我已经使用这些函数在 AppDelegate 中处理了我的通知:
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable: Any])
和:
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable: Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void)
但是点击通知后我得到了不同的反应。例如,当我有一个 deep-link 时,它在应用程序处于后台或前台时工作正常,但当应用程序关闭时,deep-link 将无法工作。
我是 IOS 的新人,如果我的问题很基础,抱歉。
当应用程序关闭并且您按下推送通知时,不会调用推送通知接收消息。相反,application:didFinishLaunchingWithOptions: 方法被调用(正如它应该的那样)。
诀窍是检查 launchOptions
词典中的通知。
if let remoteNotificationInfo = launchOptions?[.remoteNotification] as? [AnyHashable : Any] {
dealWithRemoteNotification(remoteNotificationInfo)
}
func dealWithRemoteNotification(_ userInfo:[AnyHashable : Any]) {
}
我已经使用这些函数在 AppDelegate 中处理了我的通知:
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable: Any])
和:
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable: Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void)
但是点击通知后我得到了不同的反应。例如,当我有一个 deep-link 时,它在应用程序处于后台或前台时工作正常,但当应用程序关闭时,deep-link 将无法工作。 我是 IOS 的新人,如果我的问题很基础,抱歉。
当应用程序关闭并且您按下推送通知时,不会调用推送通知接收消息。相反,application:didFinishLaunchingWithOptions: 方法被调用(正如它应该的那样)。
诀窍是检查 launchOptions
词典中的通知。
if let remoteNotificationInfo = launchOptions?[.remoteNotification] as? [AnyHashable : Any] {
dealWithRemoteNotification(remoteNotificationInfo)
}
func dealWithRemoteNotification(_ userInfo:[AnyHashable : Any]) {
}