您的位置:首页 > 移动开发

判断app是否是第一次启动

2016-06-15 13:53 411 查看
如何判断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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: