How to determine that user runs the app for the first time?

前端 未结 4 1328
故里飘歌
故里飘歌 2021-01-05 11:38

I got a problem of my iOS app recently. In my app, an instruction view will appear at the first time of running, then hide from then on. How can I implement this effect?

相关标签:
4条回答
  • 2021-01-05 11:59

    Store a file and check if the file exsists every time when you start the app. If tr file does not exsists then show intro, and then create the file.

    0 讨论(0)
  • 2021-01-05 12:00

    The only way I think is to store a value into a specified file, when run the app, you should check the value first, and then you can deal with the result whether the app has already been run.

    0 讨论(0)
  • 2021-01-05 12:05

    Try to use this function:

    - (BOOL) isFirstRun
    {
      NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];  
      if ([defaults objectForKey:@"isFirstRun"])
      {
        return NO;
      }
    
      [defaults setObject:[NSDate date] forKey:@"isFirstRun"];
      [[NSUserDefaults standardUserDefaults] synchronize];  
    
      return YES;
    }
    
    0 讨论(0)
  • 2021-01-05 12:07

    In your app delegate check for a key in the user defaults (your own custom key, something like "AppWasAlreadyStartedPreviously"). If the key doesn't exist yet, it's the first run. You can show your instruction view and add the key to the user defaults. The next time the user starts the app you'll find the key in the user defaults and know that it's not the first run.

    See the documentation of NSUserDefaults.

    0 讨论(0)
提交回复
热议问题