zoukankan      html  css  js  c++  java
  • iOS开发 检测版本更新

    iOS开发 检测版本更新的实现

    苹果给了我们一个接口,能根据应用id请求一些关于应用的信息。我们可以根据返回的信息,来判断版本是否和应用的版本一致,如果不一致,那么就出现新的版本了。这时,就需要向用户提醒有新的版本,需要更新。具体步骤如下:

      NSMutableURLRequest*request=[[NSMutableURLRequestalloc]init];

        [requestsetURL:[NSURLURLWithString:[NSStringstringWithFormat:@"http://itunes.apple.com/lookup?id=%@",appleID]]];

        [requestsetHTTPMethod:@"GET"];

        NSData*returnData=[NSURLConnectionsendSynchronousRequest:requestreturningResponse:nilerror:nil];

        NSDictionary*jsonData=[NSJSONSerializationJSONObjectWithData:returnDataoptions:0error:nil];


    这里,我们通过同步请求,解析json数据,得到了数据。
    好的,我们这里需要,version,trackViewUrl,trackName。

      NSString*latestVersion=[releaseInfoobjectForKey:@"version"];

        NSString*trackViewUrl1 =[releaseInfoobjectForKey:@"trackViewUrl"];//地址trackViewUrl

        NSString*trackName=[releaseInfoobjectForKey:@"trackName"];//trackName


    获取此应用的版本号

      NSString*currentVersion=[infoDictobjectForKey:@"CFBundleVersion"];


    通过latestVersion和currentVersion的比较,来判断是否有新的更新。

    NSDictionary*infoDict=[[NSBundlemainBundle]infoDictionary];

        NSString*currentVersion=[infoDictobjectForKey:@"CFBundleVersion"];

        doubledoubleCurrentVersion=[currentVersiondoubleValue];

        

        if(doubleCurrentVersion<doubleUpdateVersion){

            

            UIAlertView*alert;

            alert=[[UIAlertViewalloc]initWithTitle:trackName

                                               message:@"有新版本,是否升级!"

                                              delegate: self

                                     cancelButtonTitle:@"取消"

                                     otherButtonTitles: @"升级", nil];

            alert.tag = 1001;

            [alertshow];

        }

        else{

            UIAlertView*alert;

            alert=[[UIAlertViewalloc]initWithTitle:trackName

                                               message:@"暂无新版本"

                                              delegate: nil

                                     cancelButtonTitle:@"好的"

                                     otherButtonTitles: nil, nil];

            [alertshow];

        }


    如果有新的版本,那么就跳转至下载页面,这里就用到了trackViewUrl,trackViewUrl是全路径,直接请求。

     [[UIApplicationsharedApplication]openURL:[NSURLURLWithString:trackViewUrl]];

  • 相关阅读:
    阿里云centos7.2自己安装mysql5.7远程不能访问解决方案
    Delphi中的线程类
    简单说说Delphi中线程的释放
    delphi杀进程的两种方式
    delphi备份恢复剪切板(使用了GlobalLock API函数和CopyMemory)
    Delphi 7下使用Log4Delphi 0.8日志组件
    Demo+在Linux下运行(CentOS7+dotnetcore sdk)
    反射
    解析表达式树
    JS面向对象编程之:封装、继承、多态
  • 原文地址:https://www.cnblogs.com/moyunmo/p/3384961.html
Copyright © 2011-2022 走看看