【发布时间】:2023-03-29 14:38:01
【问题描述】:
接收远程推送通知时,我需要从有效负载中捕获数据,在 IOS 9 上,我使用 func 执行此操作: didReceiveRemoteNotification 在使用 swift 3.0 的 IOS 10 上,我实现了这两个功能。
@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()
}
第二个函数仅在用户触摸推送时执行
当我的应用处于后台甚至关闭时,当推送通知到达时,我需要捕获数据。
问候。 问候
【问题讨论】: