iOS开发之检查更新
iOS设备检查更新版本:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
|
#pragma mark - 检查更新
- (
void
)checkUpdateWithAPPID:(
NSString
*)APPID
{
//获取当前应用版本号
NSDictionary
*appInfo = [[
NSBundle
mainBundle] infoDictionary];
NSString
*currentVersion = [appInfo objectForKey:@
"CFBundleVersion"
];
NSString
*updateUrlString = [
NSString
stringWithFormat:@
"http://itunes.apple.com/lookup?id=%@"
,APPID];
NSURL
*updateUrl = [
NSURL
URLWithString:updateUrlString];
versionRequest = [ASIFormDataRequest requestWithURL:updateUrl];
[versionRequest setRequestMethod:@
"GET"
];
[versionRequest setTimeOutSeconds:60];
[versionRequest addRequestHeader:@
"Content-Type"
value:@
"application/json"
];
//loading view
CustomAlertView *checkingAlertView = [[CustomAlertView alloc] initWithFrame:NAVIGATION_FRAME style:CustomAlertViewStyleDefault noticeText:@
"正在检查更新..."
];
checkingAlertView.userInteractionEnabled =
YES
;
[
self
.navigationController.view addSubview:checkingAlertView];
[checkingAlertView release];
[versionRequest setCompletionBlock:^{
[checkingAlertView removeFromSuperview];
NSError
*error =
nil
;
NSDictionary
*dict = [
NSJSONSerialization
JSONObjectWithData:[versionRequest responseData] options:
NSJSONReadingMutableContainers
error:&error];
if
(!error) {
if
(dict !=
nil
) {
// DLog(@"dict %@",dict);
int
resultCount = [[dict objectForKey:@
"resultCount"
] integerValue];
if
(resultCount == 1) {
NSArray
*resultArray = [dict objectForKey:@
"results"
];
// DLog(@"version %@",[resultArray objectAtIndex:0]);
NSDictionary
*resultDict = [resultArray objectAtIndex:0];
// DLog(@"version is %@",[resultDict objectForKey:@"version"]);
NSString
*newVersion = [resultDict objectForKey:@
"version"
];
if
([newVersion doubleValue] > [currentVersion doubleValue]) {
NSString
*msg = [
NSString
stringWithFormat:@
"最新版本为%@,是否更新?"
,newVersion];
newVersionURlString = [[resultDict objectForKey:@
"trackViewUrl"
]
copy
];
DLog(@
"newVersionUrl is %@"
,newVersionURlString);
// if ([newVersionURlString hasPrefix:@"https"]) {
// [newVersionURlString replaceCharactersInRange:NSMakeRange(0, 5) withString:@"itms-apps"];
// }
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@
"提示"
message:msg delegate:
self
cancelButtonTitle:@
"暂不"
otherButtonTitles:@
"立即更新"
,
nil
];
alertView.tag = 1000;
[alertView show];
[alertView release];
}
else
{
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@
"提示"
message:@
"您使用的是最新版本!"
delegate:
self
cancelButtonTitle:
nil
otherButtonTitles:@
"确定"
,
nil
];
alertView.tag = 1001;
[alertView show];
[alertView release];
}
}
}
}
else
{
DLog(
"error is %@"
,[error debugDescription]);
}
}];
[versionRequest setFailedBlock:^{
[checkingAlertView removeFromSuperview];
CustomAlertView *alertView = [[CustomAlertView alloc] initWithFrame:NAVIGATION_FRAME style:CustomAlertViewStyleWarning noticeText:@
"操作失败,请稍候再试!"
];
[
self
.navigationController.view addSubview:alertView];
[alertView release];
[alertView selfRemoveFromSuperviewAfterSeconds:1.0];
}];
[versionRequest startSynchronous];
}
- (
void
)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(
NSInteger
)buttonIndex
{
DLog(@
"newVersionUrl is %@"
,newVersionURlString);
if
(buttonIndex) {
if
(alertView.tag == 1000) {
if
(newVersionURlString)
{
[[UIApplication sharedApplication] openURL:[
NSURL
URLWithString:newVersionURlString]];
}
}
}
}
|
来源:http://blog.csdn.net/heartofthesea/article/details/14127587
本文转自夏雪冬日博客园博客,原文链接:http://www.cnblogs.com/heyonggang/p/3539691.html,如需转载请自行联系原作者

低调大师中文资讯倾力打造互联网数据资讯、行业资源、电子商务、移动互联网、网络营销平台。
持续更新报道IT业界、互联网、市场资讯、驱动更新,是最及时权威的产业资讯及硬件资讯报道平台。
转载内容版权归作者及来源网站所有,本站原创内容转载请注明来源。
-
上一篇
Android灵魂画家的18种混合模式
image ️️ Warning!Warning!前方高能,阅读本文可能需要3分钟哦! 有什么料? 重新认识神秘的PorterDuffXfermode。 学会正确的使用PorterDuffXfermode。 收获【两张示例图】,帮助你在实际中正确的运用各种混合模式。 解密PorterDuffXfermode 先上两张示例图,大家快来保存啊! image image 注:这两张图仅用了两个强大的View完成的。【从未如此惊艳!你好,SuperTextView (v1.1) - http://www.jianshu.com/p/1b91e11e441d】,你值得拥有! 自己绘过图的筒靴一定见过或者用过mPaint.setXfermode(Xfermode xfermode),它是干什么的呢?它的作用就是将画布上的当前图像(即目标图像DST)和后面需要绘制的图像(即源图像SRC)按照一定的算法进行混合。简单点说就是把源图像SRC与目标图像DST进行混合。而ProterDuffXfermode继承自Xfermode,提供了18像素混合模式的算法,它们是由Thomas Porter和Tom Du...
-
下一篇
Android--使用Gson解析JSON数据
版权声明:本文为博主原创文章,转载请标明出处。 https://blog.csdn.net/chaoyu168/article/details/71524956 Json是一种类似于XML的通用数据交换格式,具有比XML更高的传输效率;本文将介绍两种方法解析JSON数据,需要的朋友可以参考下 Json是一种类似于XML的通用数据交换格式,具有比XML更高的传输效率. 从结构上看,所有的数据(data)最终都可以分解成三种类型: 第一种类型是标量(scalar),也就是一个单独的字符串(string)或数字(numbers),比如"北京"这个单独的词。 第二种类型是序列(sequence),也就是若干个相关的数据按照一定顺序并列在一起,又叫做数组(array)或列表(List),比如"北京,上海"。 第三种类型是映射(mapping),也就是一个名/值对(Name/value),即数据有一个名称,还有一个与之相对应的值,这又称作散列(hash)或字典(dictionary),比如"首都:北京"。 Json的规格非常简单,只用一个页面几百个字就能说清楚,而且Douglas Crockfor...
相关文章
文章评论
共有0条评论来说两句吧...
文章二维码
点击排行
推荐阅读
最新文章
- CentOS8编译安装MySQL8.0.19
- Docker快速安装Oracle11G,搭建oracle11g学习环境
- Docker使用Oracle官方镜像安装(12C,18C,19C)
- Dcoker安装(在线仓库),最新的服务器搭配容器使用
- SpringBoot2初体验,简单认识spring boot2并且搭建基础工程
- SpringBoot2配置默认Tomcat设置,开启更多高级功能
- CentOS7,8上快速安装Gitea,搭建Git服务器
- SpringBoot2全家桶,快速入门学习开发网站教程
- SpringBoot2整合MyBatis,连接MySql数据库做增删改查操作
- MySQL数据库在高并发下的优化方案