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