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

后端 未结 7 1209
萌比男神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:29

    I like to use NSUserDefaults to store an indication of the the first run.

    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];  
    if (![defaults objectForKey:@"firstRun"])
      [defaults setObject:[NSDate date] forKey:@"firstRun"];
    
    [[NSUserDefaults standardUserDefaults] synchronize];
    

    You can then test for it later...

    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];        
    if([defaults objectForKey:@"firstRun"])           
    {
      // do something or not...
    }
    

提交回复
热议问题