My app execute background fetches to update some data. In my initial view controller's viewDidLoad
method I want to detect wether my app runs for background fetch or not?
I know that it's very easy to check the app's state using this:
if ([UIApplication sharedApplication].applicationState == UIApplicationStateBackground) {
return; // have a breakpoint here <----
}
But for some reason even when I launch app normally sometimes program can reach this breakpoint. Which means that applicationState
returns UIApplicationStateBackground
. Maybe app launch happens at the moment when background fetch is running or something like that?
I don't want to execute code that in my viewDidLoad
method when app runs in background mode, so I need this if
block in viewDidLoad
.