標籤:擷取 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版本號碼與更新