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
Post a Comment