Vikings
Vikings

Reputation: 2527

iPhone didFinishLaunchingWithOptions Method

So i'm trying to use this method to load a certain theme based on what the user chose in the settings bundle. When I insert NSLog it will load the default them (Modern Theme), but it will never change to the Pink Theme.

Is this method loaded every time the app is launched, even if the app is still running in the background.

Otherwise, where else could I do this, if I want to use the settings bundle.

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{   
    NSDictionary *userDefaultsDefaults = [NSDictionary dictionaryWithObjectsAndKeys: @"Modern Theme", @"theme", nil];
    [[NSUserDefaults standardUserDefaults] registerDefaults:userDefaultsDefaults];

    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    theme =[defaults objectForKey:@"theme"];    

    NSLog(@"%@", theme);

    if ([theme isEqualToString:@"Modern Theme"]) {
        viewController = [[viewTwo alloc] initWithNibName:@"viewTwo" bundle:nil];
    }
    else {
        viewController = [[viewOne alloc] initWithNibName:@"viewOne" bundle:nil];
    }

    self.window.rootViewController = self.viewController;
    [self.window makeKeyAndVisible];

    return YES;
}

Upvotes: 2

Views: 9653

Answers (2)

Devraj
Devraj

Reputation: 3065

The method

- (void)applicationWillResignActive:(UIApplication *)application

is fired when the app is resumed from the background.

I'd nearly load the theme in the ViewController's

-(void)viewDidAppear:(BOOL)animated

method.

Upvotes: 0

aroth
aroth

Reputation: 54796

Have you tried putting your code in applicationDidBecomeActive:? That one is guaranteed to be called whether on the initial launch or resuming from the background.

Reference docs.

Upvotes: 4

Related Questions