Scene
When we use the app, an app is opened, and if the app has a new version, it's often possible to give hints in the app if you want to update the app. So, let's take a look at how the version update is implemented.
App Apple gives us an interface that can request some information about the app based on the app ID. Depending on the information returned, we can tell if the version is consistent with the version of the app, and if not, then a new version appears. At this point, you need to alert the user to a new version, which needs to be updated. The steps are as follows:?
12345 |
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init]; [request setURL:[NSURL URLWithString:[NSString stringWithFormat:@ "http://itunes.apple.com/lookup?id=%@" ,appleID]]]; [request setHTTPMethod:@ "GET" ]; NSData *returnData = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil]; NSDictionary *jsonData = [NSJSONSerialization JSONObjectWithData:returnData options:0 error:nil]; |
Here, we get the data by synchronizing the request, parsing the JSON data. Okay, we need it here, version,trackviewurl,trackname.
123 |
NSString *latestVersion = [releaseInfo objectForKey:@ "version" ]; NSString *trackViewUrl1 = [releaseInfo objectForKey:@ "trackViewUrl" ]; //地址trackViewUrl NSString *trackName = [releaseInfo objectForKey:@ "trackName" ]; //trackName |
Get the version number of this app?
1 |
NSString *currentVersion = [infoDict objectForKey:@ "CFBundleVersion" ]; |
Determine if a new update is available by comparing latestversion and CurrentVersion.
Nsdictionary *infodict = [[NSBundle mainbundle] infodictionary]; NSString *currentversion = [infodict objectforkey:@ "cfbundleversion"]; Double doublecurrentversion = [CurrentVersion Doublevalue]; if (Doublecurrentversion < doubleupdateversion) {Uialertview *alert; alert = [[Uialertview alloc] Initwithtitle:trackname message:@ "There is a new version, whether to upgrade! "Delegate:self cancelbuttontitle:@" Cancel " Otherbuttontitles: @ "Upgrade", nil]; Alert.tag = 1001; [Alert show]; } else{Uialertview *alert; alert = [[Uialertview alloc] Initwithtitle:trackname message:@ "no new version" Delegate:nil cancelbuttontitle:@ "Good" Otherbuttontitles:nil, nil]; [Alert show]; }
If there is a new version, then jump to the download page, where the use of Trackviewurl,trackviewurl is the full path, direct request.
[[UIApplication sharedapplication] Openurl:[nsurl Urlwithstring:trackviewurl]];
OK, this is all the steps of the version update.
iOS Check for version updates