检查我的IOS应用程序是否已更新

我需要检查我的应用程序是否在更新时启动,因为我需要创建一个仅在首次安装该应用程序时才出现的视图,以便在更新后再次出现。

回答:

您可以将值(例如,当前应用程序版本号)保存到其中,NSUserDefaults并在每次用户启动应用程序时对其进行检查。

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions

{

// ...

NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];

NSString *currentAppVersion = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleShortVersionString"];

NSString *previousVersion = [defaults objectForKey:@"appVersion"];

if (!previousVersion) {

// first launch

// ...

[defaults setObject:currentAppVersion forKey:@"appVersion"];

[defaults synchronize];

} else if ([previousVersion isEqualToString:currentAppVersion]) {

// same version

} else {

// other version

// ...

[defaults setObject:currentAppVersion forKey:@"appVersion"];

[defaults synchronize];

}

return YES;

}

在迅速-2版本看起来是这样的:

let defaults = NSUserDefaults.standardUserDefaults()

let currentAppVersion = NSBundle.mainBundle().objectForInfoDictionaryKey("CFBundleShortVersionString") as! String

let previousVersion = defaults.stringForKey("appVersion")

if previousVersion == nil {

// first launch

defaults.setObject(currentAppVersion, forKey: "appVersion")

defaults.synchronize()

} else if previousVersion == currentAppVersion {

// same version

} else {

// other version

defaults.setObject(currentAppVersion, forKey: "appVersion")

defaults.synchronize()

}

在迅速-3版本看起来是这样的:

let defaults = UserDefaults.standard

let currentAppVersion = Bundle.main.object(forInfoDictionaryKey: "CFBundleShortVersionString") as! String

let previousVersion = defaults.string(forKey: "appVersion")

if previousVersion == nil {

// first launch

defaults.set(currentAppVersion, forKey: "appVersion")

defaults.synchronize()

} else if previousVersion == currentAppVersion {

// same version

} else {

// other version

defaults.set(currentAppVersion, forKey: "appVersion")

defaults.synchronize()

}

以上是 检查我的IOS应用程序是否已更新 的全部内容, 来源链接: utcz.com/qa/401466.html

回到顶部