简体   繁体   中英

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

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?

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;
}

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 .

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.

我认为唯一的方法是将值存储到指定的文件中,在运行应用程序时,您应首先检查该值,然后您可以处理应用程序是否已运行的结果。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM