gpt4 book ai didi

ios - 我如何知道我的应用程序是由于后台刷新而启动的?

转载 作者:行者123 更新时间:2023-11-29 12:45:19 29 4
gpt4 key购买 nike

我的 iOS 应用程序正在使用后台刷新(通过 application:didReceiveRemoteNotification:fetchCompletionHandler: API),我注意到有时 iOS 会在后台终止应用程序并稍后重新启动它。

在这种情况下,似乎正在调用 application:didFinishLaunchingWithOptions: 但没有调用 applicationDidBecomeActive: 因为应用程序停留在后台。

我面临的挑战是我想知道我的应用程序是否由于我的 application:didFinishLaunchingWithOptions: 函数中的后台刷新而在后台重新启动,因为我在那里做了一些早期处理。这可能吗?

最佳答案

如果它是通过远程通知启动的,请查找传递给 -application:didFinishLaunchingWithOptions:

的启动 key

Keys used to access values in the launch options dictionary passed to the application:willFinishLaunchingWithOptions: and application:didFinishLaunchingWithOptions: methods of the app delegate

特别是:

UIApplicationLaunchOptionsRemoteNotificationKey
The presence of this key indicates that a remote notification is available for the app to process. The value of this key is an NSDictionary containing the payload of the remote notification. See the description of application:didReceiveRemoteNotification: for further information about handling remote notifications.

如果它是通过 NSURLSession 进行后台获取,WWDC 2013 的 Session 204 有更多信息,但是您需要实现 application:handleEventsForBackgroundURLSession:completionHandler:

enter image description here

关于ios - 我如何知道我的应用程序是由于后台刷新而启动的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23810001/

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