iOS 版本更新

作者: 一杯红酒mm | 来源:发表于2016-06-28 17:25 被阅读4792次

需求:当iOS应用迭代更新时,少不了更新提示

思路:通过获取appStore已上传的版本的版本号与手机当前该软件的plist文件中版本号对比来判断是否更新版本

直接上代码:

/**提示更新*/
- (void)upData {
    
    
    //获取手机程序的版本号
    NSString *ver = [[[NSBundle mainBundle]infoDictionary] objectForKey:@"CFBundleVersion"];
    
    
    
    AFHTTPSessionManager *mgr = [AFHTTPSessionManager manager];
    [mgr.responseSerializer setAcceptableContentTypes: [NSSet setWithObjects:@"application/json", @"text/json", @"text/javascript",@"text/html", nil]];
    //POST必须上传的字段
    NSDictionary *dict = @{@"id":@"Apple ID"};//此处的Apple ID
    [mgr POST:@"https://itunes.apple.com/lookup" parameters:dict success:^(NSURLSessionDataTask * _Nonnull task, id  _Nonnull responseObject) {
        
        
        
        NSArray *array = responseObject[@"results"];
        if (array.count != 0) {// 先判断返回的数据是否为空
            NSDictionary *dict = array[0];
            
            
            //判断版本  [dict[@"version"] floatValue] > [ver floatValue]
            if (dict[@"version"] > ver) {
                
                UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"更新" message:@"更稳定、快速、多彩的功能和体验,立即点击升级!" delegate:self cancelButtonTitle:@"关闭" otherButtonTitles:@"更新", nil] ;
                alert.delegate = self;
                alert.tag = 222;
                [alert show];
            }
        }
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
    }];
}

上面在dict中的值为Apple ID,即是AppStore上的Apple ID

Paste_Image.png

最后是AlertView的回调方法,跳到AppStore的下载地址

#pragma mark - AlertViewDelegate
- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex {

if (alertView.tag == 222) {
        
        if (buttonIndex == 1) {
            UIApplication *application = [UIApplication sharedApplication];
            [application openURL:[NSURL URLWithString:@"AppStore的下载地址"]];
        }
        
    }
}

这样就实现了App应用的版本更新

�态度决定一切

相关文章

  • iOS版本更新

    iOS APP版本 更新

  • iOS 上传AppStore 被拒汇总

    (1)、苹果要求版本更新必须使用iOS版本更新内置更新机制。 4. Design: Preamble Design...

  • iOS版本更新

    1、获取当前版本 NSString *current_version = [[[NSBundle mainBund...

  • iOS 版本更新

    获取本机版本号 NSDictionary *localDic = [[NSBundle mainBundle] i...

  • iOS版本更新

    版本更新 #pragma mark -检查版本更新 - (void)checkNewVersion { // NS...

  • iOS 版本更新

    众所周知苹果拒绝任何带有版本更新的提示出现在页面中,因此我们通过接口获取,处理是否显示更新提示。 1.判断版本号 ...

  • iOS 版本更新

    1.获取本地版本信息 2.获取App Store版本信息 3.新旧版本对比 代码: 请求的基类中获取App Sto...

  • iOS版本更新

    最近,应项目需求,简单写了一个版本更新的提示,有需要的码友可以去下载看看,实现起来比较简单。 效果图 首先是请求a...

  • iOS版本更新

    一、获取app线上版本苹果提供网址:https://itunes.apple.com/lookup网址所需参数:i...

  • iOS 版本更新

    今天公司要给APP加上“检查更新”这个服务,因为在上一家公司做过,所以没花太多时间就完成了。不过还是看以前公司的代...

网友评论

本文标题:iOS 版本更新

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