在后台处理完富推送后(用户在未打开应用的情况下点击了 UNNotificationAction - 没有前台),然后当您进入应用时,会出现重复推送事件导致“didReceiveRemoteNotification”执行。
我的问题是:
为什么当我处理富人推入时:
func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
并调用competitionHandler(),同样的推送被接收到:
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable: Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void)
?
推送设置:
UNUserNotificationCenter.current().delegate = self
UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .sound, .badge]) { (granted, error) in
if granted {
print("UNUserNotificationCenter auth granted")
Utils.performTaskOnMain {
application.registerForRemoteNotifications()
}
} else {
print("UNUserNotificationCenter auth error = \(error?.localizedDescription ?? "")")
}
推送处理程序
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable: Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void)
{
print("AppDelegate didReceiveRemoteNotification, with info:\(userInfo)")
handleNotificationUserInfo(userInfo)
completionHandler(UIBackgroundFetchResult.newData)
}
@available(iOS 10.0, *)
func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
UserNotificationsManager.shared.handleActionIdentifierForReceivedNotification(response)
completionHandler()
}
推送通知有效负载:
info:[AnyHashable("content-available"): 1, AnyHashable("messageInfo"): {"push_type":"XXXX","category":"videoCategory","mediaUrl":"https://XXXX.png","threadId":"24274","alertTitle":null,"initiator":"XXXXX XXXX.mp3","alertBody":null,"mutableContent":true}, AnyHashable("media-url"): https://XXXXX.png, AnyHashable("aps"): {
alert = {
body = "XXXXX";
};
badge = 56;
category = "XXX.videoCategory";
"content-available" = 1;
"mutable-content" = 1;
sound = "XXXX.mp3";
}]