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

前端之家收集整理的这篇文章主要介绍了检查我的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;
}

swift版本看起来像这样:

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()
}
原文链接:https://www.f2er.com/iOS/336542.html

猜你在找的iOS相关文章