objective c - iOS - comparing app versions -


i want update app on app store. when app first opened after update, want sync stuff. therefore need way see if it's first launch after update.

the solution thought of is: storing app version in nsuserdefaults this:

nsstring *oldversion = [[nsuserdefaults standarduserdefaults] objectforkey:@"appversion"]; nsstring *currentversion = [[[nsbundle mainbundle] infodictionary] objectforkey:@"cfbundleshortversionstring"]; [[nsuserdefaults standarduserdefaults] setobject:currentversion forkey:@"appversion"]; [[nsuserdefaults standarduserdefaults] synchronize]; 

now have oldversion , currentversion , need compare them. want know if oldversion smaller currentversion. strings. how can check if oldversion < currentversion?

i know can check if not equal. want prepared future updates. because maybe syncing want perform 2 different version 3 , on.

you can compare numeric version numbers using natural sort order (which consider 1.10 come after 1.1, unlike lexicographic sort order) follows:

bool isnewer = ([currentversion compare:oldversion options:nsnumericsearch] == nsordereddescending) 

Comments

Popular posts from this blog

java - Plugin org.apache.maven.plugins:maven-install-plugin:2.4 or one of its dependencies could not be resolved -

Round ImageView Android -

How can I utilize Yahoo Weather API in android -