Iphone 应用程序升级检查

标签 iphone ios objective-c migration

如何检测 objective-c 中的升级点?无论如何检测应用程序刚刚升级到更新版本或更新正在进行中。 ?

我的场景是考虑用户在他的设备中有一个应用程序版本 1.0,他正在获取更新通知并更新应用程序。版本更新后的应用程序应该在这里显示一些应用程序教程。

最佳答案

使用 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。这样对于更新后的首次启动,此 key 将不会出现在 NSUserDefaults 中,从而使 hasLaunchedBefore = NO。您可以采取必要的措施。

如果需要,您可以使用 NSUserDefaults 删除以前版本的 key ,

[[NSUserDefaults standardUserDefaults] removeObjectForKey:@"AppHasLaunchedBefore_v1.0"];

您可以通过以下方式以编程方式获取当前发布的应用程序的捆绑版本,

NSString* version = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"];
//Append this to the user default key, AppHasLaunchedBefore_v%@

希望对您有所帮助!

关于Iphone 应用程序升级检查,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18765278/

相关文章:

iOS使用socket连接发送数据

ios - 如何在我的应用程序(Swift)中检测命令 C?

ios - Swift:在 CellForRowAtIndexPath 中设置新的 UIImage 不显示

iphone - 为什么我在发送多个请求时收到此错误(HTTP 错误 400。)?

ios - SpriteKit .plist 问题 xcode 6

iphone - 如何获取 UILabel 将截断文本的范围

ios - Objective C - 滑动以从主屏幕打开应用程序

ios - 使用 Core Data 存储自定义对象

objective-c - 从具有 URL 的 WebView 打印 PDF。 Objective C macOS

ios - 增加 iOS 中标题和表格单元格之间的空间