更新时间:2023-01-25 21:49:19
最简单的方法是使用 NSUserDefaults
保存当前版本:
The easiest way is to save the current version using NSUserDefaults
:
if (![[NSUserDefaults standardUserDefaults] objectForKey:@"app_version"] || [[[NSUserDefaults standardUserDefaults] objectForKey:@"app_version"] integerValue] < [[[NSBundle mainBundle] objectForInfoDictionaryKey: @"CFBundleVersion"] integerValue]) {
// new version detected!
[[NSUserDefaults standardUserDefaults] setObject:[[NSBundle mainBundle] objectForInfoDictionaryKey: @"CFBundleVersion"] forKey:@"app_vervion"];
}
编辑为包含此功能的首次更新添加了对用户默认值存在的检查.
EDIT Added check for user defaults existence for first update containing this functionality.
编辑二我现在明白你真正想要什么.您将需要几乎与我编写的代码相同的代码:
EDIT II I now understood what you really want. You'll need almost the same code I wrote:
if (![[NSUserDefaults standardDefaults] boolForKey:@"tour_done"]) {
// present tour and that call:
// [[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"tour_done"];
// [[NSUserDefaults standardUserDefaults] synchronize];
}