ios检查版本更新
场景
在我们使用应用时,一打开应用,如果此应用有新的版本,常常能在应用中给出提示,是否要更新此应用。所以,我们就来看看,版本更新是如何实现的。
应用
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数据,得到了数据。
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检查版本更新的更多相关文章
- iOS 检查app版本更新操作
iOS 检查app版本更新操作 1:获取本地安装的版本信息: [NSString stringWithFormat:@"Version %@ (%@)", [[[NSBundle ...
- iOS 检查指定日期是否在当前日期之前
iOS检查指定日期是否在当前日期之前, 直接上代码: - (BOOL)checkProductDate: (NSString *)tempDate { NSDateFormatter *dateFor ...
- iOS 检测版本更新(02)
iOS 检测版本更新 如果我们要检测app版本的更新,那么我们必须获取当前运行app版本的版本信息和appstore 上发布的最新版本的信息. 当前运行版本信息可以通过info.plist文件中的bu ...
- ios 实现版本更新检查
注:这里网络请求用的是第三方框架:SVHTTPRequest /* 第一步: 根据应用名称搜索应用,然后根据应用绑定的ID在结果中筛选出我们要找的应用,并取出应用的AppID */ - (void)g ...
- ios 使用ASIHTTPRequest来检查版本更新
- (void) alertWithTitle: (NSString *)_title_ msg:(NSString *)msg delegate:(id)_delegate cancelButton ...
- iOS - Harpy版本更新工具兼容版本第三方库
Harpy(兼容版) git地址:https://github.com/yangchao0033/Harpy ###(iOS5-9适配版本,基于ArtSabintsev/Harpy v3.4.5) 提 ...
- iOS检查App新版本并更新新版本
检查新版本 更新 第一种方法 //检查新版本 更新 dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, ...
- iOS检测版本更新
有时候为了需求,我们需要检测app版本更新今天在这里整合下 //获取当前版本号 NSDictionary *infoDictionary = [[NSBundle mainBundle] infoDi ...
- iOS软件版本更新思路
iOS软件更新思路 需要更新版本数组 needUpdateVersions{1.2.61.2.8} 历史版本数组 historyUpdateVersions1.2.41.2.51.2.6 更新数据库1 ...
随机推荐
- jQuery选择器之基本选择器Demo
测试代码: 01-基本选择器.html <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" &quo ...
- codeforces 680B B. Bear and Finding Criminals(水题)
题目链接: B. Bear and Finding Criminals //#include <bits/stdc++.h> #include <vector> #includ ...
- 转:Android官方MVP架构示例项目解析
转自: http://www.infoq.com/cn/articles/android-official-mvp-architecture-sample-project-analysis 作者 吕英 ...
- Google Map Api 谷歌地图接口整理
一:基本知识: 1. 使用谷歌地图 API 的第一步就是要注册一个 API 密钥,需要注重一下两点: 1.假如使用 API 的页面还没有发布,只是在本地调试,可以不用密钥,随便用个字符串代替就可以了. ...
- Table of Contents - Servlet & JSP
Servlet Servlet API Overview Java Web 访问资源的路径问题 getParameter 与 request.getAttribute 的区别 转发与重定向的区别 中文 ...
- 【Mongodb】---Scheme和Collections对应问题
Mongodb通过mongoose来与数据进行操作.而mongoose是通过model来创建数据库中对应的collection mongoose.model('User', UserSchema); ...
- c#重载和重写及运用
重载的条件: 1.必须在同一个类中2.方法名必须相同3.参数列表不能相同. 重写的条件: 1. 在不同的类中 2. 发生方法重写的两个方法 ...
- c#中进程的使用
C#的Process类的一些用法 更多0 c# 进程 c#之process类相关整理 一.根据进程名获取进程的用户名? 需要添加对 System.Management.dll 的引用 usin ...
- C# 操作 Excel 常见问题收集和整理(定期更新,欢迎交流)
经常会有项目需要把表格导出为 Excel 文件,或者是导入一份 Excel 来操作,那么如何在 C# 中操作 Excel 文件成了一个最基本的问题. 做开发这几年来,陆陆续续也接触过这样的需求,但因为 ...
- 2015英特尔® 实感™ (Intel® RealSense™) 动手开发实验课
2015年英特尔® 全球实感技术动手实验课路演来到中国, 这次在中国将有北京和广州两站,包括一天的动手实验室活动 - 面向对感知计算.3D 开发和虚拟现实兴趣浓厚的开发人员.英特尔专家将会指导您如何借 ...