iOS判断程序第一次启动

 1 #import "AppDelegate.h"
 2 #import "UIImageView+WebCache.h"
 3 //NSUserDefaults 实例化
 4 #define USER_DEFAULT [NSUserDefaults standardUserDefaults]
 5 #define kisActivities            @"isActivities"
 6 
 7 @interface AppDelegate ()
 8 
 9 @end
10 
11 @implementation AppDelegate
12 
13 
14 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
15 //判断应用第一次启动-----------------------------------------------------------------
16     NSString *filePath =  [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/isFirst.plist"];
17     //读文件(项目第一次运行,沙盒中没有文件 isFirstdic = nil)
18     NSDictionary *isFirstdic =  [NSDictionary dictionaryWithContentsOfFile:filePath];
19     
20     BOOL isFirst =  [[isFirstdic objectForKey:@"isFirst"] boolValue]; //0  NO
21     //判断是否有app活动开展
22     BOOL isActivity = [[USER_DEFAULT objectForKey:kisActivities] boolValue];
23     
24     if (!isFirst || isActivity) {
25         
26         NSLog(@"第一次启动");
27         //如果是第一次启动,则启动引导页
28         NSArray* arr = @[ @"img_00", @"img_01", @"img_02", @"img_03", @"img_04" ];
29         for (int i = 0; i<arr.count; i++) {
30             [[SDImageCache sharedImageCache] storeImage:[UIImage imageNamed:arr[i]] forKey:[NSString stringWithFormat:@"img_0%d",i]];
31         }
32     }
33     //用字典在沙盒中写入文件,并将值为YES,项目以后再运行,读取到的值均为YES
34     NSDictionary *dic = @{@"isFirst" : @YES};
35     //将字典写到沙盒目录
36     [dic writeToFile:filePath atomically:YES];
37 //判断应用第一次启动-------------------------------------------------------------------
38     return YES;
39 }

 

posted @ 2015-12-24 10:35  预估计  阅读(341)  评论(0编辑  收藏  举报