判断app是否是第一次启动

如何判断app是否是第一启动呢,第一次启动的时候,加载引导页面等,

一下是我的解决方案:

1、在"AppDelegate.h"中找到- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions方法,添加如下代码:

if (![[NSUserDefaults standardUserDefaults] boolForKey:@"everLaunched"]) {
    [[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"everLaunched"];
    [[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"firstLaunch"];
}
else{
    [[NSUserDefaults standardUserDefaults] setBool:NO forKey:@"firstLaunch"];
}
总的解决办法是 2 个key: @”everLaunched”判断用户以前是否登录, 

@”firstLaunch” 用来开发者在程序的其他部分判断.

第一次启动的时候 key @”everLaunched” 不会被赋址的, 并且设置为YES. @”firstLaunch”被设置为 YES.

在程序的其他部分用以下代码判断:
if ([[NSUserDefaults standardUserDefaults] boolForKey:@"firstLaunch"]) {
        // 这里判断是否第一次
        
        hDisplayView *hvc = [[hDisplayView alloc]initWithFrame:CGRectMake(0, 0, MainScreen_width, MainScreen_height)];
        
        [self.window.rootViewController.view addSubview:hvc];
        
        [UIView animateWithDuration:0.25 animations:^{
            hvc.frame = CGRectMake(0, 0, MainScreen_width, MainScreen_height);
            
        }];
        
    }
第一段代码运行key 
@”firstLaunch” 将被设置为 NO
原文地址:https://www.cnblogs.com/hero11223/p/5587221.html