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

前端 未结 4 1353
故里飘歌
故里飘歌 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 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;
    }
    

提交回复
热议问题