Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 642
Sohaib Avatar asked Jan 11 '23 19:01

Sohaib


1 Answers

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
like image 64
FeichengMaike Avatar answered Jan 25 '23 23:01

FeichengMaike