码迷,mamicode.com
首页 > 移动开发 > 详细

判断app是否是第一次启动

时间:2016-06-15 14:24:30      阅读:292      评论:0      收藏:0      [点我收藏+]

标签:

如何判断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

 

判断app是否是第一次启动

标签:

原文地址:http://www.cnblogs.com/hero11223/p/5587221.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!