Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Do I initialize the viewController when I receive UIApplicationLaunchOptionsLocationKey in app didFinishLaunchingWithOptions?

Tags:

ios

location

I'm creating an app which listens to significant location change events and in case the app gets terminated then the iOS launches the app with UIApplicationLaunchOptionsLocationKey set.

So, the documentation says to create a new location manager and register for location updates again. However, doesn't mention if I'm supposed to initialize my viewController (as I do in normal app launch as well)? My view controllers initialize in viewDidLoad but are created in appDidFinishLaunchingWithOptions.

Any idea how much time does OS provides to the App for location update handling? My app needs to make a webservice request if the location change indicates an interested location for the app.

Thanks

like image 926
Gary Avatar asked May 08 '11 18:05

Gary


1 Answers

You should consider moving your initialization code to a new method, something like initializeViews. This method would check to make sure the views haven't been initialized and then initialize them. You would call this method from application:didFinishLaunchingWithOptions: and applicationWillEnterForeground:, but the call in application:didFinishLaunchingWithOptions: would only occur if the application wasn't going to the background.

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    ...
    if([UIApplication sharedApplication].applicationState != UIApplicationStateBackground)
        [self initializeViews];
}
- (void)applicationWillEnterForeground:(UIApplication *)application {
    [self initializeViews];
}
- (void)initializeViews {
    if(!viewsAreInitialized) {
        ...
        viewsAreInitialized = YES;
    }
}
like image 143
ughoavgfhw Avatar answered Nov 29 '22 10:11

ughoavgfhw