iOS检测更新

作者: 酷哥不回头看爆炸 | 来源:发表于2016-11-09 10:18 被阅读153次

原理:

通过appid访问 http://itunes.apple.com/lookup 可以获取appStore上本app最新版本的信息然后和当前安装的版本做比较, 如果本地低于最新版本弹框提示让用户选择是否跳转到appstore更新。

获取所安装的app版本号

    NSDictionary *infoDic = [[NSBundle mainBundle] infoDictionary];
    _LocationVersion = [infoDic objectForKey:@"CFBundleShortVersionString"];

获取appStore最新版本号 并且比较两者

示例只取最新的版本号。更多信息可以通过控制台的输出得到获取字段。

    AFWeakSelf(self);
    [[NetKit kit] GET:[NSString stringWithFormat:@"http://itunes.apple.com/lookup?id=%@",APP_ID] parameters:nil success:^(id ret) {
        AFStrongSelf(self);
        NSLog(@"最新版本信息%@",ret);
        if ([ret hasObjectWithKey:@"results"]) {
            NSArray *infoArray = ret[@"results"];
            if (infoArray.count) {
                NSDictionary *releaseInfo = [infoArray objectAtIndex:0];
                NSString *lastVersion = [releaseInfo objectForKey:@"version"];
                
                if ([_LocationVersion compare:lastVersion options:NSNumericSearch] == NSOrderedAscending)
                {
                    [UIAlertView bk_showAlertViewWithTitle:@"更新提示" message:@"发现新版本,是否立即更新?" cancelButtonTitle:@"立即更新" otherButtonTitles:@[@"以后再说"] handler:^(UIAlertView *alertView, NSInteger buttonIndex) {
                        if (buttonIndex == 0) {
                            [self PushtoAppStore:releaseInfo[@"trackViewUrl"]];
                        }
                    }];
                }
                
            }
            
        }
        
    } failure:^(NSError *error) {
        
    }];

跳转到appstore下载

- (void)PushtoAppStore:(NSString *)trackViewUrl{
    NSURL *url = [NSURL URLWithString:APP_LINK];
    [[UIApplication sharedApplication] openURL:url];
}

有先行者已经写好了封装

AYCheckVersion

相关文章

  • iOS检测更新

    原理: 通过appid访问 http://itunes.apple.com/lookup 可以获取appStore...

  • ios 检测更新

    Git地址:https://github.com/wolfhous/HSUpdateApp 1、将这文件拖入你的工...

  • iOS检测版本更新

    利用iTunes接口检查App版本更新

  • iOS 检测版本更新

  • iOS检测版本更新

    效果图 具体实现代码参考源码https://github.com/wolfhous/HSUpdateApp 文件小...

  • iOS 版本检测更新

  • iOS 检测版本更新

    在苹果的 app store 条文中,是不允许新版本提示的, 但是只要不让那些审核员知道有这个功能就可以了。启动的...

  • iOS检测更新APP

    iOS APP检查更新有两种方法: 1、在某特定的服务器上,发布和存储app最新的版本信息,需要的时候向该服务器请...

  • iOS 检测版本更新

    基于良好的用户体验,当在appStroe上线了新的版本时,提醒用户更新”新版本“是必不可少的。 版本更新的...

  • iOS App检测更新

    // 1. 获取App的版本 NSDictionary *infoDic = [[NSBundle mainBun...

网友评论

    本文标题:iOS检测更新

    本文链接:https://www.haomeiwen.com/subject/dbbzuttx.html