IOS Automatic Updates

Source: Internet
Author: User

Today to do the version of the automatic update, I think actually did not do this function necessary but after all, the boss is the eldest, then knocked on it is to see a big capitalization forget who is sorry ha

Nserror *error;

NSString *appid = @ "AppID";

NSString *urlstr = [NSString stringwithformat:@ "http://itunes.apple.com/lookup?id=%@", AppID];

Nsurl *url = [Nsurl urlwithstring:urlstr];

Nsurlrequest *request = [Nsurlrequest Requestwithurl:url];

NSData *response = [nsurlconnection sendsynchronousrequest:request returningresponse:nil Error:nil];

Nsdictionary *appindodic = [nsjsonserialization jsonobjectwithdata:response options:nsjsonreadingmutableleaves Error :&error];

if (Error) {

NSLog (@ "error---->%@", [error description]);

Return

}

Nsarray *resultsarray = [appindodic objectforkey:@ "Results"];

if (![ Resultsarray Count]) {

NSLog (@ "Error--->resul = = nil");

Return

}

Information about the store

Nsdictionary *infidic = [Resultsarray objectatindex:0];

NSLog (@ "%@", infidic);

The version number on the shelf

NSString *latestversion = [infidic objectforkey:@ "version"];

Url

_trackviewurl = [Infidic objectforkey:@ "Trackviewurl"];

Name

NSString *trackname = [infidic objectforkey:@ "TrackName"];

Nsdictionary *infodict = [[NSBundle mainbundle] infodictionary];

Current version number

NSString *currentversion = [infodict objectforkey:@ "cfbundleversion"];

NSLog (@ "%@---------------%@", currentversion,latestversion);

Double doublelatestversion = [Latestversion doublevalue];

Double doublecurrentversion = [CurrentVersion Doublevalue];

if (Doublecurrentversion < doublelatestversion) {

NSString *titleste = [NSString stringwithformat:@ "Check for updates:%@", TrackName];

NSString *messagestr = [NSString stringwithformat:@ "Discover new version (%@), whether Upgrade", latestversion];

Uialertview *alert = [[Uialertview alloc]initwithtitle:titleste message:messagestr delegate:self cancelButtonTitle:@ ' Cancel "otherbuttontitles:@" Upgrade ", nil";

Alert.delegate = self;

[Alert show];

}

-(void) Alertview: (Uialertview *) Alertview Clickedbuttonatindex: (Nsinteger) Buttonindex

{

if (Buttonindex = = 1) {

Skip to Apple Store

[[UIApplication sharedapplication] Openurl:[nsurl Urlwithstring:_trackviewurl]];

}

IOS Automatic 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.