IOS check version updates

Source: Internet
Author: User
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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.