iOS APP升级版本

//检测软件是否需要升级
-(void)checkVersion
{
    //新版本
    //NSString *newVersion;
    NSMutableArray *newVersion = [NSMutableArray array];
    //获取本地软件的版本号
    NSString *localVersion = [[[NSBundle mainBundle]infoDictionary] objectForKey:@"CFBundleVersion"];
    
    WS(weakself);
    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
    [manager POST:@"http://itunes.apple.com/lookup?id=1142068114" parameters:nil progress:^(NSProgress * _Nonnull uploadProgress) {
        
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        
        NSArray *array = responseObject[@"results"];
        NSDictionary *dict = [array lastObject];
        NSLog(@"当前版本为:%@", dict[@"version"]);
        
        [newVersion addObject:dict[@"version"]];
        [weakself isOrUp:localVersion andNew:newVersion[0]];
        
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        
    }];
 
}
/**
 *  升级(刨除1.2.2)最后的.2
 */
- (void)isOrUp:(NSString *)old andNew:(NSString *)new{
    
    NSString *msg = [NSString stringWithFormat:@"你当前的版本是V%@,发现新版本V%@,是否下载新版本?",old,new];
        MYLog(@"%@",msg);
    MYLog(@"%f,%f",[new floatValue],[old floatValue]);
        //对比发现的新版本和本地的版本
        if ([new floatValue] >= [old floatValue])
        {
            UIAlertView *createUserResponseAlert = [[UIAlertView alloc] initWithTitle:@"升级提示!" message:msg delegate:self cancelButtonTitle:@"下次再说" otherButtonTitles: @"现在升级", nil];
            [createUserResponseAlert show];
           
        }
    

}

//跳转到Appstore

- (void)upApp:(UIButton *)sender{
    
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"https://itunes.apple.com/cn/app/ding-dongsshn/id??????mt=8"]];
    
}

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值