Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Find out the first time opening the app when updated to newer version

The app's current behavior is, the user logged in once will not be logged out unless the user explicitly clicks on the logout.

I keep the user logged in, even if the user closes the app and opens it again.

When newer version of my app is released in appstore, I want to find out whether the user updated my app and opened it for the first time.

At that point I want to make them login again.

Is there a way to find out at the first time launch of the app after its been updated to latest version?

like image 729
nOOb iOS Avatar asked Mar 27 '15 15:03

nOOb iOS


People also ask

How can I tell when I first opened my iPhone?

There is no way to determine the "activation date" of any given iPhone. The best you can do is find out if it's still under warranty and when the warranty expires. There is no way to determine the "activation date" of any given iPhone.


2 Answers

Create some kind of version #'s scheme. Note: You can enable Xcode to create backups and versions whenever you make substantial changes to the code.

There are a number of ways one could create a version constant, save it, and read it back.

When you update an app from the store, there is app data that persists from the previous installed version of the app, which you can read back to determine the version and, then update that persistent data to be ready for the next update cycle.

This answer was a very popular solution in another similar question.

Or, try something like @JitendraGandhi's ObjC answer below, or if you use Swift, try something like my port of @JitendraGandhi's ObjC example to Swift:

func hasAppBeenUpdatedSinceLastRun() -> Bool {
    var bundleInfo = Bundle.main.infoDictionary!
    if let currentVersion = bundleInfo["CFBundleShortVersionString"] as? String {
        let userDefaults = UserDefaults.standard

        if userDefaults.string(forKey: "currentVersion") == (currentVersion) {
            return false
        }
        userDefaults.set(currentVersion, forKey: "currentVersion")
        userDefaults.synchronize()
        return true
    } 
    return false;
}
like image 92
clearlight Avatar answered Sep 28 '22 09:09

clearlight


You can save your currentversion to NSUserDefaults and use this method to check your version every time the app awakes:

#pragma mark - NSBundle Strings
- (NSString *)currentVersion
{
    return [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleShortVersionString"];
}

if the currentversion is different from stored... its time to show the login! Hope it helps you.

like image 21
Javier Flores Font Avatar answered Sep 28 '22 11:09

Javier Flores Font