在iOS 10上,didReceiveRemoteNotification方法没有被触发

时间:2016-09-26 09:42:16

标签: ios objective-c swift ios10

在iOS 10上,当用户通过点击推送通知启动应用时,didReceiveRemoteNotification方法不会被触发。 如何解决这个问题?

1 个答案:

答案 0 :(得分:1)

我认为你需要为ios 10.0做什么

import UserNotifications
   // didFinishLaunchingWithOptions method
 if #available(iOS 10.0, *) {
        let center = UNUserNotificationCenter.currentNotificationCenter()
        center.delegate = self
        center.requestAuthorizationWithOptions([.Alert, .Sound, .Badge], completionHandler: { (granted, error) in
            // do nothing for now
        })
    }

添加扩展程序

extension AppDelegate: UNUserNotificationCenterDelegate {

@available(iOS 10.0, *)
func userNotificationCenter(center: UNUserNotificationCenter, didReceiveNotificationResponse response: UNNotificationResponse, withCompletionHandler completionHandler: () -> Void) {
    // When app is killed and or in background tapping on this will resut this event
    let payload = Payload(dict: response.notification.request.content.userInfo)
    triggerThePaylod(payload)
}

}

我希望它能帮到你