简体   繁体   中英

How to determine if application is launched to do Background Fetch

When OS launch the application for background fetch the sequence I observed is this

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions

and then

-(void)application:(UIApplication *)application performFetchWithCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler

In didFinishLaunching I am trying to determine if app is launched to do Background Fetch because I need to disable some features to speedup the app loading. UIApplication doesn't expose any property to determine this.

I've noticed UIApplication has _applicationFlags which has isHandlingBackgroundContentFetch boolean which is set to true for Background Fetch but its inside @package and can't be accessed.

Sorry this isn't exactly a direct answer to your question, but can you achieve the same result by dividing your application launch logic between the following methods within your app delegate?

1) Any app startup logic that is common to both scenarios goes inside here:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions

2) Normal launch behavior goes here:

- (void)applicationDidBecomeActive:(UIApplication *)application

3) Background fetch launch behavior goes here (slimmed down version of what is in #2):

-(void)application:(UIApplication *)application performFetchWithCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM