iOS Check for version updates

Source: Internet
Author: User

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"];//地址trackViewUrlNSString *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

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.