【发布时间】:2013-09-12 21:41:31
【问题描述】:
如何检测目标 C 中的升级点?无论如何都可以检测到该应用程序刚刚升级到较新版本或正在进行更新。 ?
我的情况是,假设用户在他的设备中有一个应用程序版本 1.0,他正在收到更新通知并更新应用程序。这里以后版本更新app应该要展示一些app教程了。
【问题讨论】:
标签: iphone ios objective-c migration
如何检测目标 C 中的升级点?无论如何都可以检测到该应用程序刚刚升级到较新版本或正在进行更新。 ?
我的情况是,假设用户在他的设备中有一个应用程序版本 1.0,他正在收到更新通知并更新应用程序。这里以后版本更新app应该要展示一些app教程了。
【问题讨论】:
标签: iphone ios objective-c migration
使用NSUserDefaults 检查应用是否首次启动。
//In applicationDidFinishLaunching:withOptions:
BOOL hasLaunchedBefore = [[NSUserDefaults standardUserDefaults] boolForKey:@"AppHasLaunchedBefore_v1.0"];
if(!hasLaunchedBefore) {
//First launch
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"AppHasLaunchedBefore_v1.0"];
}
else {
//Not first launch
}
当您将应用程序更新到 2.0 版时(假设)将上述密钥修改为 AppHasLaunchedBefore_v2.0。这种方式在更新后首次启动时,此密钥将不会出现在 NSUserDefaults 和 hasLaunchedBefore = NO 中。您可以采取必要的措施。
如果需要,您可以使用 NSUserDefaults 删除以前的版本密钥,
[[NSUserDefaults standardUserDefaults] removeObjectForKey:@"AppHasLaunchedBefore_v1.0"];
您可以通过编程方式获取当前发布应用的捆绑版本,
NSString* version = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"];
//Append this to the user default key, AppHasLaunchedBefore_v%@
希望有帮助!
【讨论】:
AppHasLaunchedBefore_v3.0。更新后,第一次运行时,应用程序将检查并且此密钥将不存在。因此,您的代码可以安全地假定它在应用更新后首次启动。