iOS to determine if the app has an update available in AppStore

Source: Internet
Author: User

itunes can provide app version information, mainly through AppID, such as http://itunes.apple.com/lookup?id=946449501, when using only to find your own AppID in itunes Change to your own AppID

Use HTTP mode to read this link to get the JSON string for app information

Post part of the code

-(void) checkversion{asiformdatarequest *request = [asiformdatarequest requestwithurl:[nsurl URLWithString:strURL]]    //strurl for your AppID address [request setrequestmethod:@ "POST"];    [Request Setdelegate:self]; [Request startasynchronous];} -(void) requestfinished: (ASIHTTPRequest *) request{nsstring *recstr = [[NSString alloc] Initwithdata:    Request.responsedata encoding:nsutf8stringencoding]; RECSTR = [Recstr stringbytrimmingcharactersinset:[nscharacterset whitespaceandnewlinecharacterset]];// The returned string has a number of newline characters in front of it and needs to be removed nsdictionary *resultdic = [Jsonhelper deserializerdictionary:recstr];//    Jsonhelper is the JSON parsing class that I encapsulated, and you can parse nsarray *infoarray = [resultdic objectforkey:@ "Results"] in your own way;        if (Infoarray.count > 0) {nsdictionary* releaseinfo =[infoarray objectatindex:0];        nsstring* appstoreversion = [releaseinfo objectforkey:@ "version"];        Nsdictionary *infodic = [[NSBundle mainbundle] infodictionary]; NSString *currentversion = [Infodic objectforkey:@ "Cfbundleshortversionstring"];        Nsarray *curverarr = [CurrentVersion componentsseparatedbystring:@ ".];        Nsarray *appstoreverarr = [Appstoreversion componentsseparatedbystring:@ ".];        BOOL needupdate = NO;        Compare version number size int MAXV = (int) MAX (curverarr.count, Appstoreverarr.count);        int cver = 0;        int aver = 0; for (int i = 0; i < MAXV; i++) {if (Appstoreverarr.count > i) {aver = [NSString stringwi            thformat:@ "%@", Appstoreverarr[i]].intvalue;            } else{aver = 0;            } if (Curverarr.count > i) {cver = [nsstring stringwithformat:@ "%@", Curverarr[i]].intvalue;            } else{cver = 0;                } if (Aver > Cver) {needupdate = YES;            Break }}//If an update is available if (needupdate) {trackviewurl = [[NSStringAlloc] Initwithstring:[releaseinfo objectforkey:@ "Trackviewurl"]];//trackviewurl temporary variable storage app, can let app jump to AppStore UIA lertview* alertview =[[uialertview alloc] initwithtitle:@ "version Upgrade" Message:[nsstring stringwithformat:@ "found a new version, upgrade?            "] delegate:self cancelbuttontitle:@" Temporarily do not upgrade "otherbuttontitles:@" immediately upgrade ", Nil];                    [Alertview show]; }}}-(void) Alertview: (Uialertview *) Alertview Clickedbuttonatindex: (Nsinteger) buttonindex{if (buttonindex        = = 1) {uiapplication *application = [UIApplication sharedapplication];    [Application Openurl:[nsurl Urlwithstring:trackviewurl]; }}

iOS to determine if the app has an update available in AppStore

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.