判断app是否是第一次启动
2016-06-15 13:53
411 查看
如何判断app是否是第一启动呢,第一次启动的时候,加载引导页面等,
一下是我的解决方案:
1、在"AppDelegate.h"中找到- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions方法,添加如下代码:
一下是我的解决方案:
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。
相关文章推荐
- iOS平台基于ffmpeg的视频直播技术揭秘
- Android VideoView中getDuration()方法使用问题
- ios学习路线—Objective-C(装箱和拆箱)
- iOS 宏(define)与常量(const)的正确使用
- android 实现车轮滚动效果
- 【Android】Android 中ListView setOnItemClickListener点击无效原因分析
- 怎么升级iOS10教程
- ANDROID L - Material Design详解(视图和阴影)
- JSONObject返回到前端转化出错
- Unity3d--控制摄像机的视野范围
- Androidapk美化
- Android Studio多渠道打包
- android gridview画分割线,如图:
- android 获取文件夹、文件的大小 以B、KB、MB、GB 为单位
- Android控件GridView之仿支付宝钱包首页带有分割线的GridView九宫格的完美实现
- 支付宝 sdk 调试
- 如何使用AndroidStudio将开源项目library发布到jcenter
- iOS 计算 UIWebView 的高度的问题
- iOS导航栏随滑动渐隐渐现且不影响push页面导航栏的实现方式
- e+创业:炒散App搵银更快趣