在软件下载安装完成后,第一次启动往往需要显示一个新手操作引导,来告诉用户怎么操作这个app,这就需要在程序一开始运行就判断程序是否第一次启动,如果是,则显示新手操作引导节视图,如果不是,则进入其他视图。
可以使用NSUserDefaults这个单例来判断程序是否第一次启动,在
AppDelegate.m这个文件中的didFinishLaunchingWithOptions函数中加入下面这段单例的代码:
#import "AppDelegate.h"
@interface AppDelegate ()
@end
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// 使用NSUserDefaults来判断程序是否第一次启动
NSUserDefaults *TimeOfBootCount = [NSUserDefaults standardUserDefaults];
if (![TimeOfBootCount valueForKey:@"time"]) {
[TimeOfBootCount setValue:@"sd" forKey:@"time"];
NSLog(@"第一次启动");
}else{
NSLog(@"不是第一次启动");
}
NSLog(@"启动成功");
return YES;
}
这样当第一次启动时会打印
2016-04-28 15:19:01.291 160428boke[1716:148586] 第一次启动
2016-04-28 15:19:01.291 160428boke[1716:148586] 启动成功
以后启动时会打印
2016-04-28 15:19:39.065 160428boke[1720:149112] 不是第一次启动
2016-04-28 15:19:39.066 160428boke[1720:149112] 启动成功