iOS擷取當前AppStore版本號碼與更新

來源:互聯網
上載者:User

標籤:擷取   https   ctf   lookup   task   val   string   object   new   

 1 - (void)checkUpdateWithAppID:(NSString *)appID success:(void (^)(NSDictionary *resultDic , BOOL isNewVersion ,NSString * newVersion , NSString * currentVersion))success failure:(void (^)(NSError *error))failure{ 2     AFHTTPSessionManager *manager = [AFHTTPSessionManagermanager]; 3     manager.requestSerializer=[AFHTTPRequestSerializerserializer]; 4     manager.responseSerializer=[AFHTTPResponseSerializerserializer]; 5  6     // 7     NSString *encodingUrl=[[@"http://itunes.apple.com/lookup?id=" stringByAppendingString:@"APP的唯一ID"]stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; 8      9     [manager GET:encodingUrl parameters:nilprogress:^(NSProgress *_Nonnull downloadProgress) {10         11     } success:^(NSURLSessionDataTask *_Nonnull task, id _Nullable responseObject) {12         13         NSDictionary *resultDic=[NSJSONSerializationJSONObjectWithData:responseObject options:NSJSONReadingMutableLeaveserror:nil];14  15 //擷取AppStore的版本號碼16         NSString * versionStr =[[[resultDic objectForKey:@"results"]objectAtIndex:0]valueForKey:@"version"];17         18         NSString *versionStr_int=[versionStr stringByReplacingOccurrencesOfString:@"."withString:@""];19 20         int version=[versionStr_intintValue];21         22 //擷取本地的版本號碼23         NSDictionary *infoDic=[[NSBundle mainBundle] infoDictionary];24         25         NSString * currentVersion = [infoDic valueForKey:@"CFBundleShortVersionString"];26         27         NSString *currentVersion_int=[currentVersion stringByReplacingOccurrencesOfString:@"."withString:@""];28         29         int current=[currentVersion_int intValue];30         31         if(version>current){32             success(resultDic,YES, versionStr,currentVersion);33         }else{34             success(resultDic,NO ,versionStr,currentVersion);35         }36     } failure:^(NSURLSessionDataTask *_Nullable task, NSError *_Nonnull error) {37         failure(error);38     }];39 }40 41 42 //  調用43 44 45 VersionUpdate *tool=[[VersionUpdatealloc]init];46     __weaktypeof(self)weakSelf=self;47     [tool checkUpdateWithAppID:@""success:^(NSDictionary *resultDic,BOOL isNewVersion, NSString *newVersion , NSString * currentVersion) {48         if (isNewVersion) {//表示要更新版本49             NSMutableDictionary *dict=[[NSMutableDictionary alloc]init];50             NSString *key=[NSString stringWithFormat:@"%@%@",currentVersion,newVersion];51             NSString *value=[s.versionUpdateMessage objectForKey:key];52             int time =[value intValue];53             if (time<3&&_versionUpdateVC==nil) {//小於三次可以繼續彈框54                 time+=1;55                 [dict setValue:[NSString stringWithFormat:@"%d",time]forKey:key];56                 s.versionUpdateMessage=[NSDictionary dictionaryWithDictionary:dict];57                 _versionUpdateVC = [[VersionUpdateController alloc]initWithContent:[[[resultDic objectForKey:@"results"]firstObject]objectForKey:@"releaseNotes"]];//releaseNotes,AppStore上面的APP更新內容58                 [_versionUpdateVC addSelfFromSuperWithVersionStr:newVersion];59             }else{//大於三次不做任何操作60                 [weakSelf joinGroupView];61             }62         }63     } failure:^(NSError *error) {64         [weakSelf joinGroupView];65     }];

 

iOS擷取當前AppStore版本號碼與更新

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.