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,如需转载请自行联系原作者

目录
相关文章
|
1月前
|
API 数据安全/隐私保护 iOS开发
利用uni-app 开发的iOS app 发布到App Store全流程
利用uni-app 开发的iOS app 发布到App Store全流程
88 3
|
3月前
|
存储 iOS开发
iOS 开发,如何进行应用的本地化(Localization)?
iOS 开发,如何进行应用的本地化(Localization)?
122 2
|
3月前
|
存储 数据建模 数据库
IOS开发数据存储:什么是 UserDefaults?有哪些替代方案?
IOS开发数据存储:什么是 UserDefaults?有哪些替代方案?
39 0
|
3月前
|
安全 编译器 Swift
IOS开发基础知识: 对比 Swift 和 Objective-C 的优缺点。
IOS开发基础知识: 对比 Swift 和 Objective-C 的优缺点。
93 2
|
3月前
|
API 开发工具 iOS开发
iOS 开发高效率工具包:10 大必备工具
iOS 开发高效率工具包:10 大必备工具
48 1
|
3月前
|
API 数据安全/隐私保护 iOS开发
利用uni-app 开发的iOS app 发布到App Store全流程
利用uni-app 开发的iOS app 发布到App Store全流程
54 1
|
9天前
|
API 定位技术 iOS开发
IOS开发基础知识:什么是 Cocoa Touch?它在 iOS 开发中的作用是什么?
【4月更文挑战第18天】**Cocoa Touch** 是iOS和Mac OS X应用的核心框架,包含面向对象库、运行时系统和触摸优化工具。它提供Mac验证的开发模式,强调触控接口和性能,涵盖3D图形、音频、网络及设备访问API,如相机和GPS。是构建高效iOS应用的基础,对开发者至关重要。
12 0
|
24天前
|
开发工具 Swift iOS开发
利用SwiftUI构建动态用户界面:iOS开发新范式
【4月更文挑战第3天】 随着苹果不断推进其软件开发工具的边界,SwiftUI作为一种新兴的编程框架,已经逐渐成为iOS开发者的新宠。不同于传统的UIKit,SwiftUI通过声明式语法和强大的功能组合,为创建动态且响应式的用户界面提供了一种更加简洁高效的方式。本文将深入探讨如何利用SwiftUI技术构建具有高度自定义能力和响应性的用户界面,并展示其在现代iOS应用开发中的优势和潜力。
|
2月前
|
监控 API Swift
用Swift开发iOS平台上的上网行为管理监控软件
在当今数字化时代,随着智能手机的普及,人们对于网络的依赖日益增加。然而,对于一些特定场景,如家庭、学校或者企业,对于iOS设备上的网络行为进行管理和监控显得尤为重要。为了满足这一需求,我们可以利用Swift语言开发一款iOS平台上的上网行为管理监控软件。
200 2
|
3月前
|
数据可视化 iOS开发
iOS 开发,什么是 Interface Builder(IB)?如何使用 IB 构建用户界面?
iOS 开发,什么是 Interface Builder(IB)?如何使用 IB 构建用户界面?
40 4