zoukankan      html  css  js  c++  java
  • iOS 获取当前app的 App Store 版本号

    NSString * strurl = [[NSString alloc] initWithFormat:@"http://itunes.apple.com/lookup?id=%@",AppIDs];//替换为自己App的ID
            NSURLSession *session=[NSURLSession sharedSession];
            NSURL *url = [NSURL URLWithString:strurl];
            
            //3.创建可变的请求对象
            NSMutableURLRequest *request=[NSMutableURLRequest requestWithURL:url];
            NSURLSessionDataTask *dataTask = [session dataTaskWithRequest:request completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error){
                //8.解析数据
                NSDictionary *dict=[NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:nil];
                NSArray * results = dict[@"results"];
                NSDictionary * dic = results.firstObject;
                NSString * lineVersion = dic[@"version"];//版本号
                NSString * releaseNotes = dic[@"releaseNotes"];//更新说明
                NSString * trackViewUrl = dic[@"trackViewUrl"];//链接
                NSLog(@"App store版本号:%@",lineVersion);
                NSLog(@"更新说明:%@",releaseNotes);
                NSLog(@"App下载链接:%@",trackViewUrl);
                
                NSCharacterSet *nonDigitCharacterSet = [[NSCharacterSet decimalDigitCharacterSet] invertedSet];
                //获取字符串中的数字
                self.applocalversion = [[self.applocalversion componentsSeparatedByCharactersInSet:nonDigitCharacterSet] componentsJoinedByString:@""];//本地的app版本
                lineVersion = [[lineVersion componentsSeparatedByCharactersInSet:nonDigitCharacterSet] componentsJoinedByString:@""];//App store的app版本
                NSLog(@"结果是本地的app版本:%@ 
     App store的app版本:%@ ",self.applocalversion,lineVersion);
                
                // 获取NSUserDefaults对象
                NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
                [defaults setObject:lineVersion forKey:@"App_store_version"];
                [defaults synchronize];  //如果要立刻保存就需要这行代码
                
                if ([lineVersion integerValue]>[self.applocalversion integerValue]) {//App store的app版本>//本地的app版本 时要提醒升级
                    dispatch_async(dispatch_get_main_queue(), ^{
                        self.nav.tabBarItem.badgeValue = @"new";
                    });
                }else{
                    NSLog(@"111没有新版本不用更新提示");
                }
                
            }];
            //7.执行任务
            [dataTask resume];
  • 相关阅读:
    关于SQL优化(转载,格式有调整)
    开篇(我想有个家,安稳的家)
    常见兼容问题
    BFC概念及应用
    浏览器私有前缀及内核
    css3新增属性
    宽高自适应
    css布局
    css3选择器
    常用标签
  • 原文地址:https://www.cnblogs.com/gaozhang12345/p/11451289.html
Copyright © 2011-2022 走看看