The original check code for the project applies to the 1.2 1.3 format. The general normal project format should be 1.2.2, so large version. Small version format.
Paste the code
-(void) oncheckversion{dispatch_queue_t queue = dispatch_get_global_queue (Dispatch_queue_priority_default, 0); Dispatch_async (queue, ^{nsdictionary *infodic = [[NSBundle mainbundle] infodictionary]; NSString *currentversion = [infodic objectforkey:@ "cfbundleshortversionstring"]; NSString *url = @ "Http://itunes.apple.com/lookup?id=xxx"; Nsmutableurlrequest *request = [[Nsmutableurlrequest alloc] init]; [Request Seturl:[nsurl Urlwithstring:url]; [Request sethttpmethod:@ "POST"]; Nshttpurlresponse *urlresponse = nil; Nserror *error = nil; NSData *recerveddata = [nsurlconnection sendsynchronousrequest:request returningresponse:&urlresponse Error: &error]; NSString *results = [[nsstring alloc] initwithbytes:[recerveddata bytes] length:[recerveddata length] Encoding: Nsutf8stringencoding]; Nsdictionary *dic = [nsjsonserialization jsonobjectwithdata:[results datausingencoding:nsutf8stringencoding] OptioNs:kniloptions Error:nil]; Nsarray *infoarray = [dic objectforkey:@ "Results"]; if ([Infoarray count]) {nsdictionary *releaseinfo = [Infoarray objectatindex:0]; NSString *lastversion = [releaseinfo objectforkey:@ "version"]; if ([self versionnumberconversion:lastversion] >[self versionnumberconversion:currentversion]) {alert = [Uialertcontroller alertcontrollerwithtitle:@ "discover new version" Message:[releaseinfo objectforkey:@ "ReleaseNotes"] Preferredstyle:uialertcontrollerstylealert]; Uialertaction *cancelaction = [uialertaction actionwithtitle:@ "temporarily not" style:uialertactionstylecancel Handler:nil]; [Alert addaction:cancelaction]; Uialertaction *sureaction = [uialertaction actionwithtitle:@ "Update" Style:uialertactionstyledefault handler:^ ( Uialertaction * _nonnull action) {//Nsurl *url = [Nsurl urlwithstring:@] Https://itunes.apple.com/cn/ap P/xxname/idxxx?l=en&mt=8 "]; Nsurl *url = [Nsurl urlwithstring:@ "itms-apps://itunes.apple.com/cn/app/xxname/idxxx?mt=8"]; [[UIApplication Sharedapplication]openurl:url]; }]; [Alert addaction:sureaction]; Dispatch_async (Dispatch_get_main_queue (), ^{[self presentviewcontroller:alert animated:yes completion : nil]; }); } } });}
-(int) Versionnumberconversion: (nsstring*) version{ //If the version number 1.5.1 the following side need to determine several decimals, to determine the number of arrays. int num1 = 0; Nsarray *ary = [version componentsseparatedbystring:@ "]; if (Ary.count) {for (int i = 0; i<ary.count; i++) { if (i==0) { NUM1 = [ary[0] intvalue]*10000; } else if (i==1) { NUM1 = [ary[0] intvalue]*10000+[ary[1] intvalue]*100; } else if (i==2) { NUM1 = [ary[0] intvalue]*10000+[ary[1] intvalue]*100+[ary[2] intvalue]; } else if (i>=3) { NUM1 = [ary[0] intvalue]*10000+[ary[1] intvalue]*100+[ary[2] intvalue];}} //nslog (@ "version number%d", NUM1); return NUM1;}
iOS Check for version updates