1

I'm trying to play an intro movie when my app is getting launch, but am totally driven crazy already, I did a lot of testing in my code, along with trying to use this

 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
 {
     // Override point for customization after application launch.
     NSLog(@"App started to launch");
     [self.window makeKeyAndVisible];
     [self.window addSubview:_intro.view];
     return YES;
 }

but that's make my video run, even if I'm coming from the background.
If like pressing the middle button, then double pressing the middle button and pressing app icon, I get the movie to play again.

I forget to mention that this is my ViewDidLoad

- (void)viewDidLoad    
{
    [super viewDidLoad];
    NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
    BOOL launchedBefore = [userDefaults boolForKey:@"hasRunBefore"];
    NSLog(@"value of hasRunBefore is %d",launchedBefore);
    if(!launchedBefore)
    {
        [userDefaults setBool:1 forKey:@"hasRunBefore"];
        launchedBefore = [userDefaults boolForKey:@"hasRunBefore"];   
        NSLog(@"value of hasRunBefore is %d",launchedBefore);
        [self playvideo];
    }
}
vikingosegundo
  • 52,040
  • 14
  • 137
  • 178
Ahmed
  • 11
  • 1

1 Answers1

1

NSUserDefaults does not commit the changes to disk until you send the synchronize message.

Try adding doing this:

[userDefaults setBool:YES forKey:@"hasRunBefore"];
[userDefaults synchronize];
  • It doesn't work :( I tried puttin it after every change in value, but no luck. I think didFinishLaunchingWithOptions is running after time I got from background to foreground. – Ahmed Jun 15 '11 at 18:26
  • I've made it zero when going to background and 1 when coming to foreground it works, thanks a lot. – Ahmed Jun 15 '11 at 18:48
  • Cool, glad it worked. You might want to accept the answer then. – Martin Adoue Jun 16 '11 at 16:29