iOS疯狂讲义之--应用程序版本新特性设置详解

来源:互联网 发布:仿砍柴网源码破解版 编辑:程序博客网 时间:2024/06/06 06:47
#import "AppDelegate.h"
#import "NewFeatureViewController.h"
#import "RootTabBarController.h"
@interface AppDelegate ()

@end

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    
// 根据应用程序的版本号设置是否显示新特性
    
    // 取出沙盒中上次使用的版本号

    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];

   // @"lastVersion"可自定义

    NSString *lastVersion = [defaults stringForKey:@"lastVersion"];

    // 取出当前版本号信息(注意:@"CFBundleVersion"请与相应的.plist文件中的key一致)

    NSString *currentVersion = [NSBundle mainBundle].infoDictionary[@"CFBundleVersion"];
    // 比较两个版本是否一样
    if ([currentVersion isEqualToString:lastVersion]) {
        // 显示状态栏
        application.statusBarHidden = NO;
        self.window.rootViewController = [[RootTabBarController alloc] init];
    } else { // 有新版本
        self.window.rootViewController = [[NewFeatureViewController alloc] init];
        // 存储新版本
        [defaults setValue:currentVersion forKey:@"lastVersion"];
        // 进行同步
        [defaults synchronize];
    }
    
    self.window.backgroundColor = [UIColor grayColor];
    [self.window makeKeyAndVisible];
    return YES;
}

@end
1 0
原创粉丝点击