您的位置:首页 > 移动开发 > IOS开发

ios开发之《版本控制》

2016-01-04 19:26 471 查看
摘要:当我们第一次使用某app或者是更新版本后打开某app时,我们会发现会由一个app简介,让我们可以了解app的一些特色功能或者说事更新之后的改进,这里就讲解一下怎么做到这样的版本控制。

在AppDelegate里面实现该功能。

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {

// 创建窗口
self.window = UIWindow()
self.window?.frame = UIScreen.mainScreen().bounds

let versionKey: String = "CFBundleVersion"

// 从沙盒中取出上次存储的软件版本号(取出用户上次的使用记录)
let defaults = NSUserDefaults.standardUserDefaults()
let lastVersion = defaults.objectForKey(versionKey) as? NSString

// 获得当前打开软件的版本号
let currentVersion = NSBundle.mainBundle().infoDictionary![versionKey] as! NSString

if(lastVersion?.isEqualToString(currentVersion as String) == true) { // 当前版本号 == 上次使用的版本号
self.window?.rootViewController = MainViewController()
}else {  // 当前版本号 != 上次使用的版本号
self.window?.rootViewController = NewFeatureViewController()
//  存储这次使用的软件版本号
defaults.setObject(currentVersion, forKey: versionKey)
//  立即存储版本号
defaults.synchronize()
}
return true
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: