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]];

  • 相关阅读:
    01--DNS服务器3
    01--DNS服务器2
    装配bean
    实现二级域名
    apache反向代理
    struts拓展restful
    restful是什么
    struts的声明式异常处理
    linux常用命令之压缩打包
    linux常用命令之文件系统
  • 原文地址:https://www.cnblogs.com/moyunmo/p/3384961.html
Copyright © 2011-2022 走看看