场景

在我们使用应用时,一打开应用,如果此应用有新的版本,常常能在应用中给出提示,是否要更新此应用。所以,我们就来看看,版本更新是如何实现的。

应用

苹果给了我们一个接口,能根据应用id请求一些关于应用的信息。我们可以根据返回的信息,来判断版本是否和应用的版本一致,如果不一致,那么就出现新的版本了。这时,就需要向用户提醒有新的版本,需要更新。具体步骤如下:
1
2
3
4
5
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
[request setURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://itunes.apple.com/lookup?id=%@",appleID]]];
[request setHTTPMethod:@"GET"];
NSData *returnData = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
NSDictionary *jsonData = [NSJSONSerialization JSONObjectWithData:returnData options:0 error:nil];

这里,我们通过同步请求,解析json数据,得到了数据。

好的,我们这里需要,version,trackViewUrl,trackName。
1
2
3
NSString *latestVersion = [releaseInfo objectForKey:@"version"];
NSString *trackViewUrl1 = [releaseInfo objectForKey:@"trackViewUrl"];//地址trackViewUrl
NSString *trackName = [releaseInfo objectForKey:@"trackName"];//trackName

获取此应用的版本号

1
NSString *currentVersion = [infoDict objectForKey:@"CFBundleVersion"];

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

NSDictionary *infoDict = [[NSBundle mainBundle] infoDictionary];
NSString *currentVersion = [infoDict objectForKey:@"CFBundleVersion"];
double doubleCurrentVersion = [currentVersion doubleValue]; if (doubleCurrentVersion < doubleUpdateVersion) { UIAlertView *alert;
alert = [[UIAlertView alloc] initWithTitle:trackName
message:@"有新版本,是否升级!"
delegate: self
cancelButtonTitle:@"取消"
otherButtonTitles: @"升级", nil];
alert.tag = 1001;
[alert show];
}
else{
UIAlertView *alert;
alert = [[UIAlertView alloc] initWithTitle:trackName
message:@"暂无新版本"
delegate: nil
cancelButtonTitle:@"好的"
otherButtonTitles: nil, nil];
[alert show];
}

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

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:trackViewUrl]];

好的,这就是版本更新的全部步骤。

ios检查版本更新的更多相关文章

  1. iOS 检查app版本更新操作

    iOS 检查app版本更新操作 1:获取本地安装的版本信息: [NSString stringWithFormat:@"Version %@ (%@)", [[[NSBundle ...

  2. iOS 检查指定日期是否在当前日期之前

    iOS检查指定日期是否在当前日期之前, 直接上代码: - (BOOL)checkProductDate: (NSString *)tempDate { NSDateFormatter *dateFor ...

  3. iOS 检测版本更新(02)

    iOS 检测版本更新 如果我们要检测app版本的更新,那么我们必须获取当前运行app版本的版本信息和appstore 上发布的最新版本的信息. 当前运行版本信息可以通过info.plist文件中的bu ...

  4. ios 实现版本更新检查

    注:这里网络请求用的是第三方框架:SVHTTPRequest /* 第一步: 根据应用名称搜索应用,然后根据应用绑定的ID在结果中筛选出我们要找的应用,并取出应用的AppID */ - (void)g ...

  5. ios 使用ASIHTTPRequest来检查版本更新

    - (void) alertWithTitle: (NSString *)_title_ msg:(NSString *)msg delegate:(id)_delegate cancelButton ...

  6. iOS - Harpy版本更新工具兼容版本第三方库

    Harpy(兼容版) git地址:https://github.com/yangchao0033/Harpy ###(iOS5-9适配版本,基于ArtSabintsev/Harpy v3.4.5) 提 ...

  7. iOS检查App新版本并更新新版本

    检查新版本 更新  第一种方法 //检查新版本 更新 dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, ...

  8. iOS检测版本更新

    有时候为了需求,我们需要检测app版本更新今天在这里整合下 //获取当前版本号 NSDictionary *infoDictionary = [[NSBundle mainBundle] infoDi ...

  9. iOS软件版本更新思路

    iOS软件更新思路 需要更新版本数组 needUpdateVersions{1.2.61.2.8} 历史版本数组 historyUpdateVersions1.2.41.2.51.2.6 更新数据库1 ...

随机推荐

  1. 剑指Offer23 二叉树中和为sum的路径

    /************************************************************************* > File Name: 23_FindPa ...

  2. 转:http range 用法与说明

    转: http://www.cnblogs.com/Googler/archive/2010/08/19/1803700.html HTTP RANGE Range,是在 HTTP/1.1(http: ...

  3. 【转载】MQTT学习笔记——MQTT协议体验 Mosquitto安装和使用

    http://blog.csdn.net/xukai871105/article/details/39252653 0 前言     MQTT是IBM开发的一个即时通讯协议.MQTT是面向M2M和物联 ...

  4. js标签放在html的什么位置比较好

    推荐的是js的script标签放在body的末尾,</body>标签之前,包含在body内! <body> <!--其它Html标签--> <script&g ...

  5. part 2 Angular modules and controllers

    What is a module in AngularJS? A module is a container for different parts of your application i.e c ...

  6. 关于柯尼卡美能达bizhub250出现c2557错误解决方法

    打印机出现c2557代码的操作方法 1.         按效用/计数器键 英文是(Utility/Counter) 2.         看到有检查细息(Check Detail) 3.       ...

  7. 在调用“Fill”前,SelectCommand 属性尚未初始化

    在调用“Fill”前,SelectCommand 属性尚未初始化 是因为少写了一行代码: private readonly string strConnection = System.Configur ...

  8. 关于strong、copy、weak、assign的常规用法

    strong   对于普通的OC对象都是使用strong copy     对于 NSString,Block weak    用于OC对象,1.当出现循环强引用的时候,必须要保证一端是weak, 2 ...

  9. c#高级编程第七版 学习笔记 第一章 .NET体系结构

    第一章      .NET体系结构 本章内容: 编译和运行面向.NET的代码 Microsoft中间语言(Microsoft Intermediate Language,MSIL或简称IL)的优点 值 ...

  10. Session State Pattern会话状态模式

    Client Session State 客户会话状态. 在Client端保存会话状态. 运行机制 Client在每次请求时会把所有的会话数据传给Server,Server在响应时把所有的会话状态传给 ...