Best way to check if an iPhone app is running for the first time

后端 未结 7 1218
萌比男神i
萌比男神i 2020-11-28 22:19

I want to check if my iPhone app is running for the first time. I can create a file in the documents folder and check that file to see if this is the first time the app is r

7条回答
  •  难免孤独
    2020-11-28 22:40

    In your app delegate register a default value:

    NSDictionary *defaultsDict = 
    [[NSDictionary alloc] initWithObjectsAndKeys:[NSNumber numberWithBool:YES], @"FirstLaunch", nil];
    [[NSUserDefaults standardUserDefaults] registerDefaults:defaultsDict];
    [defaultsDict release];
    

    Then where you want to check it:

    NSUserDefaults *sharedDefaults = [NSUserDefaults standardUserDefaults];
    if ([sharedDefaults boolForKey:@"FirstLaunch"]) {
      //Do the stuff you want to do on first launch
      [sharedDefaults setBool:NO forKey:@"FirstLaunch"];
      [sharedDefaults synchronize];
    }
    

提交回复
热议问题