zoukankan      html  css  js  c++  java
  • iOS 如何实现实时版本更新

    转载请注明出处!!!

    虽然苹果禁止应用内更新,但是有时候仍需要弹出更新提示。但是iOS审核需要时间,如何实时获取信息判断是否更新呢。我们可以获取App Store中app的信息来判断。代码如下:

    - (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
    
        // 1.直接请求苹果商店信息
    
        [self getAppStoreAppInfoWithAppID:APPID];
    
    }
    
     
    
    - (void)getAppStoreAppInfoWithAppID:(NSString *)appId {
    
        AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
    
       
    
        // 可不写
    
        [manager.responseSerializer setAcceptableContentTypes: [NSSet setWithObjects:@"application/json", @"text/json", @"text/javascript",@"text/html", nil]];
    
        
    
        // 必传信息
    
        NSDictionary *dict = @{@"id":appId};//此处的Apple ID
    
        
    
        [manager POST:@"https://itunes.apple.com/lookup" parameters:dict progress:^(NSProgress * _Nonnull uploadProgress) {
    
            
    
        } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
    
            
    
            
    
            NSArray *array = responseObject[@"results"];
    
            if (array.count != 0) {// 先判断返回的数据是否为空
    
                NSDictionary *dict = array[0];
    
        NSDictionary *infoDic = [[NSBundle mainBundle] infoDictionary];
    
                NSString *currentAppVersion = infoDic[@"CFBundleShortVersionString"];
    
                NSString *newVersion =[NSString stringWithFormat:@"%@版本更新",dict[@"version"]];
    
                // 也可以判断不一样就行。那样简单
    
                if ([dict[@"version"] compare:currentAppVersion options:NSNumericSearch] == NSOrderedDescending) {
    
                    NSLog(@"需要更新");
    
                    
    
                } else {
    
                    NSLog(@"不需要更新");
    
                }
    
     
    
            }
    
            
    
        } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
    
            
    
        }];
    
    }

     返回结果图如下:

  • 相关阅读:
    node-sass 安装失败
    js中复制功能总结
    设置NODE_ENV=test环境变量
    js eslint语法规范错误提示代码
    npm安装node包时怎么显示安装进度
    前端面试题总结三
    5种方式将数字转成千分位
    前端面试题总结二(js原型继承)
    前端面试题总结一(js变量和函数声明提前相关)
    1109 Group Photo (25分)
  • 原文地址:https://www.cnblogs.com/weicyNo-1/p/7508434.html
Copyright © 2011-2022 走看看