I want to check whether my app was launched for background fetch in my application delegate's didFinishLaunchingWithOptions. There is nothing in launchOptions dictionary. So is there any way to check it?
I know that I can check applicationState
, but for some reason sometimes it returns UIApplicationStateBackground, even if I launch app normally.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
if (application.applicationState != UIApplicationStateBackground) {
// Analytics initialization code
}
}
I've created breakpoint at Analytics initialization code and sometimes it enters to this block even if I launch app normally!
I know that I can detect the state later when applicationDidBecomeActive
or applicationDidEnterBackground
will be called. If I will use these approach to detect the state I need to move my Analytics initialization code to some other place. If it remain in application:didFinishLaunchingWithOptions:
it will be called every time when my app starts background fetch. So maybe I should just move Analytics initialization code to some other method and don't check applicationState
in application:didFinishLaunchingWithOptions:
? If so which method I can use for this?