gpt4 book ai didi

ios - 当我的应用程序处于后台或关闭状态时,远程推送通知到达时从负载获取数据

转载 作者:搜寻专家 更新时间:2023-10-30 22:14:59 25 4
gpt4 key购买 nike

当收到远程推送通知时,我需要从有效负载中捕获数据,在 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()
}

第二个函数仅在用户触摸推送时执行

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

问候。问候

最佳答案

当收到推送通知并且您的应用未运行时,您需要在 didFinishLaunchingWithOptions 中实现您的通知逻辑:

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// Called when a notification is tapped and the app wasn't running, not in foreground neither in background.
if let userInfo = launchOptions?[UIApplicationLaunchOptionsKey.remoteNotification] as? [String: AnyObject]{
// your logic here!
}
}

关于ios - 当我的应用程序处于后台或关闭状态时,远程推送通知到达时从负载获取数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39899892/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com