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

 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     }];

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值