当我的应用处于后台或关闭时远程推送通知到达时从有效负载获取数据

Chr*_*lez 6 ios swift swift3

我需要在重新发送远程推送通知时从有效负载中捕获数据,在IOS 9上我使用func执行此操作:didReceiveRemoteNotification在IOS 10上使用swift 3.0我实现了这两个功能.

@available(iOS 10.0, *)
func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void)
{
print("\(notification.request.content.userInfo)")

completionHandler([.alert, .badge, .sound])
}

@available(iOS 10.0, *)
func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void)
{
print("User Info = ",response.notification.request.content.userInfo)

completionHandler()
}
Run Code Online (Sandbox Code Playgroud)

第二个功能仅在用户触摸推送时执行

当我的应用程序处于后台甚至关闭时,我需要在推送通知到达时捕获数据.

问候.问候

小智 0

尝试使用 iOS10 中的 didReceiveRemoteNotification 函数:

    func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any]) {

                   print(userInfo)

             }
Run Code Online (Sandbox Code Playgroud)