码迷,mamicode.com
首页 > 移动开发 > 详细

iOS获取当前AppStore版本号与更新

时间:2016-11-29 07:05:40      阅读:362      评论:0      收藏:0      [点我收藏+]

标签:获取   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版本号与更新

标签:获取   https   ctf   lookup   task   val   string   object   new   

原文地址:http://www.cnblogs.com/luorende/p/6111796.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!