import <Foundation/Foundation.h>
@interface TJXTool : NSObject
+(BOOL)isFirstStarApp;
@end
import "TJXTool .h"
@implementation TJXTool
+(BOOL)isFirstStarApp{
//保证key值得唯一性,一个key只能对应一个对象,代表app启动次数
NSString *key = @"appStarNumber";
//获得
NSUserDefaults *def = [NSUserDefaults standardUserDefaults];
NSNumber *number = [def objectForKey:key];
if(number.integerValue > 0){
//不是第一次,
//上次启动次数+1
// NSString *num = [def objectForKey:@"appStarNumber"];
// NSInteger num1 = num.integerValue;
// num1 += 1;
// [def setObject:num1 forKey:key];
number = [NSNumber numberWithInteger:number.integerValue+1];
[def setObject:number forKey:key];
[def synchronize];
NSLog(@"这是第%ld启动",number.integerValue);
return NO;
}else{
//是第一次,
//赋值,下次启动不再是0
number = [NSNumber numberWithInteger:1];
//赋值
[def setObject:number forKey:key];
//同步到磁盘
[def synchronize];
NSLog(@"第一次启动");
return YES;
}
return YES;
}
@end