iOS 软件更新代码实现

这里用的升级方法是通过访问appStore获取版本号进行对比的, 如果公司内有提供版本的接口, 也可以使用公司的接口进行判断, 步骤都一样

//检测软件是否需要升级
- (void)checkVersion{
 dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
        NSURL *url = [NSURL URLWithString:@"http://itunes.apple.com/cn/lookup?id=391945719"];
        NSData *jsonResponseData = [NSData dataWithContentsOfURL:url];

        if (jsonResponseData) {
            dispatch_async(dispatch_get_main_queue(), ^{
                NSString *newVersion;
                //解析json数据为数据字典
                NSDictionary *loginAuthenticationResponse = [self dictionaryFromJsonFormatOriginalData:jsonResponseData];
                JJLog(@"%@",loginAuthenticationResponse);
                //从数据字典中检出版本号数据
                NSArray *configData = [loginAuthenticationResponse valueForKey:@"results"];
                for(id config in configData)
                {
                    newVersion = [config valueForKey:@"version"];
                }

                NSLog(@"通过appStore获取的版本号是:%@",newVersion);

                //获取本地软件的版本号
                NSString *localVersion = [[[NSBundle mainBundle]infoDictionary] objectForKey:@"CFBundleVersion"];

                NSString *msg = [NSString stringWithFormat:@"你当前的版本是V%@,发现新版本V%@,是否下载新版本?",localVersion,newVersion];

                //对比发现的新版本和本地的版本
                if ([newVersion floatValue] > [localVersion floatValue])
                {

                    UIAlertView *createUserResponseAlert = [[UIAlertView alloc] initWithTitle:@"升级提示!" message:msg delegate:self cancelButtonTitle:@"下次再说" otherButtonTitles: @"现在升级", nil];
                    [createUserResponseAlert show];
                }
            });

        }

    });
}

//响应升级提示按钮
- (void)alertView:(UIAlertView *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
    //如果选择“现在升级”
    if (buttonIndex == 1)
    {
        //打开iTunes  方法一
        //这个链接在iTunes上面我的App-App信息-额外信息-在AppStore中查看即可获得该地址
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"https://itunes.apple.com/cn/app/wan-zhuan-quan-cheng/id391945719?mt=8"]];
         // 打开iTunes 方法二:此方法总是提示“无法连接到itunes”,不推荐使用
         NSString *iTunesLink = @"itms-apps://phobos.apple.com/WebObjects/MZStore.woa/wa/viewSoftwareUpdate?id=692579125&mt=8";
         //打开iTunes  方法三(我目前使用的方法)
         NSString *iTunesLink = @"itms-apps://itunes.apple.com/cn/app/id10593231"
         [[UIApplication sharedApplication] openURL:[NSURL URLWithString:iTunesLink]];
         */
    }
}

注:app的id是在第一次在iTunes上创建应用的时候, 会有提供id, 然后在到这里面去提交你要发布的版本就好, 具体可以度娘如果发布应用

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值