- 获得项目中info.plist 文件的内容
1> [NSBundle mainBundle].infoDictionary
2> 版本号在info.plist 中的key :kCFBundleVersionKey
2.沙盒的数据存储及读取
1> 数据存储:
[[NSUserDefaults standardUserDefaults] setObject:version forKey:versionKey];
存储数据时记得同步一下 [[NSUserDefaults standardUserDefaults] synchronize]; 这两句话一般是成对存在的
2> 数据读取:
[[NSUserDefaults standardUserDefaults] objectForKey:versionKey];
(1,2)小知识点综合例子: 沙盒中存储版本号并读取版本号和应用程序里的版本号对比是否相同 来判断所要跳转的根视图控制器
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary )launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
/
二、判断用户是否第一次使用这个版本
1.将沙盒中的版本号和info.plist中的版本号进行比较
2.第一次使用:显示版本新特性界面
3.非第一次使用:显示主界面(显示状态栏)
*/
// 1.从info.plist字典中取出版本号
NSString *versionKey = (NSString *)kCFBundleVersionKey;
NSString *version = [[NSBundle mainBundle] objectForInfoDictionaryKey:versionKey];
// 2.取出存在于沙盒中的版本号
NSString *saveVersion = [[NSUserDefaults standardUserDefaults] objectForKey:versionKey];
// 3.判断info.plist中的版本号和沙盒中的版本号进行比较
if ([saveVersion isEqualToString:version]) { // 版本号相同 非第一次使用:显示主界面(显示状态栏)
// 显示状态栏
application.statusBarHidden = NO;
self.window.rootViewController = [[MainViewController alloc]init];
}
else // 版本号不同 非第一次使用:显示主界面(显示状态栏)
{
[[NSUserDefaults standardUserDefaults] setObject:version forKey:versionKey];
[[NSUserDefaults standardUserDefaults] synchronize]; // 同步
self.window.rootViewController = [[NewFeatureViewController alloc] init];
}
[self.window makeKeyAndVisible];
return YES;
}
网友评论