iOS 11应通过应用程序委派方法或仅通过取消委派方法处理推送通知

iOS 11应通过应用程序委派方法或仅通过取消委派方法处理推送通知,ios,swift,push-notification,appdelegate,unusernotificationcenter,Ios,Swift,Push Notification,Appdelegate,Unusernotificationcenter,我一直在寻找一个直截了当的答案,但还没有找到一个,所以我想在这里问我的问题。对于post iOS 10应用程序,远程通知应由 应用程序委托方法: func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetc

我一直在寻找一个直截了当的答案,但还没有找到一个,所以我想在这里问我的问题。对于post iOS 10应用程序,远程通知应由

应用程序委托方法:

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

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

}
或者,取消授权方法:

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

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

}

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

否则,如果您能够坚持iOS10后版本的支持,我会首选
UNUserNotificationCenter
,因为
UIApplicationLegate
将来可能会被弃用

如果您使用的是WatchKit,
DidReceiveMemotentification
已被弃用,请不要使用它。从:

不使用此方法,而是创建采用 UnuseNotificationCenterDelegate协议并实现 userNotificationCenter:willPresentNotification:withCompletionHandler: 和 userNotificationCenter:didReceiveNotificationResponse:withCompletionHandler: 方法。将此对象指定给singleton的delegate属性 UNUserNotificationCenter对象