Quantcast
Channel: Check if my IOS application is updated - Stack Overflow
Viewing all articles
Browse latest Browse all 9

Answer by tilo for Check if my IOS application is updated

$
0
0

You could save a value (e.g. the current app version number) to NSUserDefaults and check it every time the user starts the app.

- (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;}

The version looks like this:

let defaults = NSUserDefaults.standardUserDefaults()let currentAppVersion = NSBundle.mainBundle().objectForInfoDictionaryKey("CFBundleShortVersionString") as! Stringlet 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()}

The version looks like this:

let defaults = UserDefaults.standardlet currentAppVersion = Bundle.main.object(forInfoDictionaryKey: "CFBundleShortVersionString") as! Stringlet 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()}

Viewing all articles
Browse latest Browse all 9

Trending Articles