Scenario
When we use an application, when we open the application, if the application has a new version, we can often give a prompt in the application, whether to update the application. So let's take a look at how version updates are implemented.
The application Apple gave us an interface to request information about the application based on the Application ID. We can determine whether the version is consistent with the application version based on the returned information. if the version is different, a new version will appear. In this case, you need to remind the user of a new version that needs to be updated. The procedure is as follows:
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. Here we need to: version, trackviewurl, and trackname.
Nsstring * latestversion = [releaseinfo objectforkey: @ "version"]; nsstring * trackviewurl1 = [releaseinfo objectforkey: @ "trackviewurl"]; // address trackviewurl nsstring * trackname = [releaseinfo objectforkey: @ "trackname"]; // trackname
Obtain the application version number.
NSString *currentVersion = [infoDict objectForKey:@"CFBundleVersion"];
Compare latestversion with CurrentVersion to determine whether a new update exists.
Nsdictionary * infodict = [[nsbundle mainbundle] infodictionary]; nsstring * CurrentVersion = [infodict objectforkey: @ "cfbundleversion"]; double doublecurrentversion = [CurrentVersion doublevalue]; if) {uialertview * alert; Alert = [[uialertview alloc] initwithtitle: trackname message: @ "new version available, upgrade required! "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: @ "okay" otherbuttontitles: nil, nil]; [alert show];}
If a new version is available, go to the download page and use trackviewurl. trackviewurl is a full path and is directly requested.
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:trackViewUrl]];
Okay. This is all the steps for updating the version.