gpt4 book ai didi

ios - 手动杀死应用程序时调用哪个方法或远程推送通知到达时如何处理

转载 作者:行者123 更新时间:2023-11-30 12:58:55 30 4
gpt4 key购买 nike

应用程序远程通知在应用程序处于前台或后台状态时工作正常,但在手动终止应用程序时不起作用,

在 plist 中添加后台获取。

尝试过:

 NSLog("Do something") 

在这种方法下仍然无法在swift中接收:

func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) 

 func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable: Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void)

最佳答案

当您手动终止应用程序时,在应用程序再次启动之前无法处理远程通知。

当存在远程通知,并且您通过点击该通知打开应用程序时,应用程序将以通常的方式启动,并显示

didFinishLaunchingWithOptions

在应用程序委托(delegate)中调用的方法。但在这种情况下,您的通知数据将在“选项”参数中传递。然后您可以检查此参数并执行所需的任务

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool
{

if (launchOptions != nil)
{
let dictionary:NSDictionary = launchOptions?[UIApplicationLaunchOptionsRemoteNotificationKey] as! NSDictionary
self.setNotification(dictionary)
}

return true
}

关于ios - 手动杀死应用程序时调用哪个方法或远程推送通知到达时如何处理,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40080344/

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