App detects version updates on AppStore

Source: Internet
Author: User

AppStore case, version check for upgrade processing

#define KSHIPERAPPID @"AppStore view AppID"

#define KURLLOOKUP @"http://itunes.apple.com/cn/lookup?id=%@"



#pragmaMark-appstore Check for Updates-(void) Checkupdate: (ID) sender{__weaktypeof(self) wself =Self ; [Mbprogresshud ShowHUDAddedTo:self.window Animated:yes]; Dispatch_async (Dispatch_get_global_queue (Dispatch_queue_priority_default,0), ^(){ //nsstring *url = [NSString stringwithformat:kurllookup,@ "423084029"]; //if ([Self.type isequaltostring:@ "shipper"]) {NSString *url =[NSString Stringwithformat:kurllookup,kshiperappid]; // }Nsmutableurlrequest *request =[[Nsmutableurlrequest alloc] init]; [Request Seturl:[nsurl Urlwithstring:url]; [Request Sethttpmethod:@"GET"]; NSData*returndata =[nsurlconnection sendsynchronousrequest:request returningresponse:nil Error:nil]; Nsdictionary*result = [nsjsonserialization jsonobjectwithdata:returndata options:0Error:nil]; NSString*serverv =@""; NSString*servinfo =@""; Do { if(!result) { Break; } IDary = result[@"Results"]; if(!ary | | NO = [ary Iskindofclass:[nsarrayclass]]) { Break; } if([(nsarray*) ary Count] <=0) { Break; } nsdictionary* Dict = ary[0]; if(!dict) { Break; } Serverv= [Dict Objectforkey:@"version"]; Servinfo= [Dict Objectforkey:@"releasenotes"]; } while(NO); Dispatch_async (Dispatch_get_main_queue (),^() {[Mbprogresshud HideAllHUDsForView:wself.window animated:yes]; NSString* Currver = [[NSBundle mainbundle] Objectforinfodictionarykey:@"cfbundleshortversionstring"]; if([currver length] = =0) {Currver= [[NSBundle mainbundle] Objectforinfodictionarykey: (NSString *) Kcfbundleversionkey]; } if(Serverv.length >0&& nsordereddescending = =[self verseioncompare:currver ver2compare:serverv]) {NSString* Tipmsg = [NSString stringWithFormat:@"discover NEW:%@\r\n%@", Serverv,servinfo]; Uialertview*alert =[[Uialertview Alloc]initwithtitle:nil message:tipmsg Delegate: Self cancelbuttontitle:@"Cancel"Otherbuttontitles:@"Update", nil]; [Alert show]; }Else{//If the latest version is not a reminder//[Self showmessagewith:@ "Your current version is the latest version"]; //nsstring* tipmsg = [NSString stringwithformat:@ "Found new version:%@\r\n%@", Serverv,servinfo]; // //Uialertview *alert = [[Uialertview alloc]initwithtitle:nil//message:tipmsg//delegate:self//cancelbuttontitle:@ "Cancel"//otherbuttontitles:@ "Update", nil]; //[alert show]; } }); });}
#pragmaMark-alertview delegate-(void) Alertview: (Uialertview *) Alertview Clickedbuttonatindex: (nsinteger) buttonindex{if(Buttonindex = =0) {NSLog (@"Quxiao"); }Else{NSLog (@"gengxin"); //[[uiapplication sharedapplication] openurl:[nsurl urlwithstring:[nsstring stringwithformat:@ "http://itunes.apple.com/cn/app/id%@ "@" 423084029 "]]; //American Regiment test can be used        if([Kpublicchanel isequaltostring:@"AppStore"] {[[uiapplication sharedapplication] Openurl:[nsurl urlwithstring:[nsstring stringWithFormat:@"http://itunes.apple.com/cn/app/id%@", Kshiperappid]]; }        Else{[[uiapplication sharedapplication] Openurl:[nsurl URLWithString:self.latestVersionPath]]; }    }}

App detects version updates on 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.