zoukankan      html  css  js  c++  java
  • iOS 关于版本升级问题的解决

    从iOS8系统开始,用户可以在设置里面设置在WiFi环境下,自动更新安装的App。此功能大大方便了用户,但是一些用户没有开启此项功能,因此还是需要在程序里面提示用户的。

    虽然现在苹果审核不能看到版本提示更新的功能和字样以及功能。但是有的app策划还是要提供这些功能。这里主要提供两种思路。

    方法一

    在服务器接口约定对应的数据,这样,服务器直接传递信息,提示用户有新版本,可以去商店升级

    但是这个方法是有问题的,由于您的app在审核过程中 不能出现更新字样,所以在审核过程中就需要接口的返回的字段是新版本,这个时候老用户就会收到更新提示,但是新版本还在审核过程中。行不通。

    解决方法

    还是需要后台配合,你可以在发送请求的时候 把你当前的版本号 发送给后台 让后台去判断 该不该返回更新版本的信息。

    方法二

    检测手机上安装的app版本 然后给App store上的版本信息对比判断(目前最常用的方法)

    步骤一:获取当前运行版本的信息 通过info.plist的bundle version获取

    NSDictionary *infoDic = [[NSBundle mainBundle] infoDictionary];
    //当前版本号
    NSString *currentVersion = [infoDic objectForKey:@"CFBundleShortVersionString"];

    步骤二:获取appstore中的app版本信息

    -(void)judgeAppVersion{<br>  //AppStore访问地址(重点)
        NSString *urlStr = @"https://itunes.apple.com//lookup?id=AppID";
        NSURL *url = [NSURL URLWithString:urlStr];
        NSURLRequest *req = [NSURLRequest requestWithURL:url];
        [NSURLConnection connectionWithRequest:req delegate:self];
    }
    #pragma mark - NSURLConnectionDataDelegate
    -(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data{
        NSError *error;<br>  //解析
        NSDictionary *appInfo = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingAllowFragments error:&error];
        NSArray *infoContent = [appInfo objectForKey:@"results"];
        //最新版本号
        NSString *version = [[infoContent objectAtIndex:0] objectForKey:@"version"];
        //应用程序介绍网址(用户升级跳转URL)
        NSString *trackViewUrl = [[infoContent objectAtIndex:0] objectForKey:@"trackViewUrl"];
    }

    解析从AppStore获取到的App信息(这里就只介绍重点使用到的信息)

    minimumOsVersion = "8.0";         //App所支持的最低iOS系统
    fileSizeBytes = ;                 //应用的大小
    releaseDate = "";                 //发布时间
    trackCensoredName = "";           //审查名称      
    trackContentRating = "";          //评级 
    trackId = ;                       //应用程序ID
    trackName = "";                   //应用程序名称
    trackViewUrl = "";                //应用程序介绍网址
    version = "4.0.3";                //版本号

    步骤三:判断当前线上App的版本号与所使用的App版本号是否一致

    if (![version isEqualToString:currentVersion]) {
            [SimplifyAlertView alertWithTitle:@"检查更新:i店" message:[NSString stringWithFormat:@"发现新版本(%@),是否升级",version] operationResult:^(NSInteger selectedIndex) {
                if (selectedIndex == 1) {
                    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:trackViewUrl]];
                }
            } cancelButtonTitle:@"取消" otherButtonTitles:@"升级", nil];
     }
  • 相关阅读:
    MySQL 数据类型
    MySQL的相关概念介绍
    遍历Map的四种方法
    Hadoop在win7下部署的问题
    Hbase之shell操作
    问题-"Record not found or changed by another user"
    问题-Delphi编译到最后Linking时总是出现与ntdll.dll有关的错误还有Fatal Error Out of memory错误
    教程-CXGRID之cxDropDownEdit密密
    问题-delphi在某电脑(win7)上是界面超乱 DPL
    教程-Delphi调用C# WEBSERVICE(二)
  • 原文地址:https://www.cnblogs.com/huanying2000/p/6187946.html
Copyright © 2011-2022 走看看