iOS get current AppStore version number with update

Source: Internet
Author: User

1- (void) Checkupdatewithappid: (NSString *) AppID success: (void(^) (Nsdictionary *resultdic, BOOL isnewversion, NSString * newversion, NSString * currentversion)) Success Failure: (void(^) (Nserror *error)) failure{2Afhttpsessionmanager *manager =[Afhttpsessionmanagermanager];3Manager.requestserializer=[Afhttprequestserializerserializer];4Manager.responseserializer=[Afhttpresponseserializerserializer];5 6//7NSString *encodingurl=[[@"http://itunes.apple.com/lookup?id="Stringbyappendingstring:@"Unique ID of the app"]stringbyaddingpercentescapesusingencoding:nsutf8stringencoding];8     9[Manager Get:encodingurl parameters:nilprogress:^ (nsprogress *_nonnull downloadprogress) {Ten          One} success:^ (Nsurlsessiondatatask *_nonnull task,ID_nullable Responseobject) { A          -Nsdictionary *resultdic=[Nsjsonserializationjsonobjectwithdata:responseobject Options:NSJSONReadingMutableLeaveserror:nil]; -   the //gets the version number of the AppStore -NSString * Versionstr =[[[resultdic Objectforkey:@"Results"]objectatindex:0]valueforkey:@"version"]; -          -NSString *versionstr_int=[versionstr stringbyreplacingoccurrencesofstring:@"."Withstring:@""]; +  -         intversion=[Versionstr_intintvalue]; +          A //get the local version number atNsdictionary *infodic=[[NSBundle Mainbundle] infodictionary]; -          -NSString * CurrentVersion = [Infodic valueforkey:@"cfbundleshortversionstring"]; -          -NSString *currentversion_int=[currentversion stringbyreplacingoccurrencesofstring:@"."Withstring:@""]; -          in         intCurrent=[Currentversion_int intvalue]; -          to         if(version>Current ) { + success (Resultdic,yes, versionstr,currentversion); -}Else{ the success (Resultdic,no, versionstr,currentversion); *         } $} failure:^ (Nsurlsessiondatatask *_nullable task, Nserror *_nonnull Error) {Panax Notoginseng failure (error); -     }]; the } +  A  the //called +  -  $Versionupdate *tool=[[Versionupdatealloc]init]; $__weaktypeof (self) weakself=Self ; -[Tool Checkupdatewithappid:@""success:^ (nsdictionary *resultdic,bool isnewversion, NSString *newversion, NSString *CurrentVersion) { -         if(isnewversion) {//indicates that you want to update the version theNsmutabledictionary *dict=[[Nsmutabledictionary alloc]init]; -NSString *key=[nsstring stringWithFormat:@"%@%@", currentversion,newversion];WuyiNSString *value=[S.versionupdatemessage Objectforkey:key]; the             intTime =[value intvalue]; -             if(time<3&&_versionupdatevc==nil) {//less than three times to continue the bullet box Wutime+=1; -[Dict setvalue:[nsstring stringWithFormat:@"%d", Time]forkey:key]; AboutS.versionupdatemessage=[Nsdictionary dictionarywithdictionary:dict]; $_VERSIONUPDATEVC = [[Versionupdatecontroller alloc]initwithcontent:[[[resultdic Objectforkey:@"Results"]firstobject]objectforkey:@"releasenotes"]];//Releasenotes,appstore The above app update content - [_versionupdatevc addselffromsuperwithversionstr:newversion]; -}Else{//More than three times do not do any action - [Weakself Joingroupview]; A             } +         } the} failure:^ (Nserror *error) { - [Weakself Joingroupview]; $}];

iOS get current AppStore version number with update

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.