OGeek|极客世界-中国程序员成长平台

标题: iOS 11 应该由 App Delegate 方法或仅由 UNDelegate 方法处理推送通知 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-11 20:02
标题: iOS 11 应该由 App Delegate 方法或仅由 UNDelegate 方法处理推送通知

我一直在寻找一个直接的答案,但还没有遇到,所以我假设在这里问我的问题。对于 iOS 10 后的应用,远程通知应该由

处理

应用委托(delegate)方法:

 func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {

}

或者,UNDelegate 方法:

 func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {

}



Best Answer-推荐答案


TVOS 不支持 UserNotificationsUI.framework,因此如果您需要支持 TVOS,请坚持使用原始 UIApplicationDelegate 方法。

否则,UNUserNotificationCenter 是我的首选,如果您可以坚持使用 iOS10 后的支持,因为将来可能会弃用 UIApplicationDelegate。 p>

如果您使用的是 WatchKit,则不推荐使用 didReceiveRemoteNotification,请勿使用它。来自 documentation :

Instead of using this method, create a delegate object that adopts the UNUserNotificationCenterDelegate protocol and implement the userNotificationCenter:willPresentNotification:withCompletionHandler: and userNotificationCenter:didReceiveNotificationResponse:withCompletionHandler: methods. Assign this object to the delegate property of the singleton UNUserNotificationCenter object.

关于iOS 11 应该由 App Delegate 方法或仅由 UNDelegate 方法处理推送通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49858992/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://ogeek.cn/) Powered by Discuz! X3.4