iOS开发之检查更新

iOS开发之检查更新

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

            }

        }

    }

}

时间: 2024-08-06 11:56:32

iOS开发之检查更新的相关文章

IOS开发语言Swift入门连载---集合类型

IOS开发语言Swift入门连载-集合类型 Swift语言提供经典的数组和字典两种集合类型来存储集合数据.数组用来按顺序存储相同类型的数据.字典虽然无序存储相同类型数据值但是需要由独有的标识符引用和寻址(就是键值对). Swift语言里的数组和字典中存储的数据值类型必须明确. 这意味着我们不能把不正确的数据类型插入其中. 同时这也说明我们完全可以对获取出的值类型非常自信. Swift 对显式类型集合的使用确保了我们的代码对工作所需要的类型非常清楚,也让我们在开发中可以早早地找到任何的类型不匹配错

iOS开发tips-神奇的UITableView

概述 UITableView是iOS开发中使用频率最高的UI控件,在前面的文章中对于UITableView的具体用法有详细的描述,今天主要看一些UITableView开发中的常见一些坑,这些坑或许不深,但是如果开发中注意不到的话往往比较浪费时间. 神奇的section header 事情的起因是一个网友说要实现一个类似下图界面,但是不管是设置sectionHeaderHeight还是代理方法中实现func tableView(_ tableView: UITableView, heightFor

iOS开发网络篇—文件的上传

iOS开发网络篇—文件的上传 说明:文件上传使用的时POST请求,通常把要上传的数据保存在请求体中.本文介绍如何不借助第三方框架实现iOS开发中得文件上传. 由于过程较为复杂,因此本文只贴出部分关键代码. 主控制器的关键代码: YYViewController.m 1 #import "YYViewController.h" 2 3 #define YYEncode(str) [str dataUsingEncoding:NSUTF8StringEncoding] 4 5 @inter

iOS开发UI篇—推荐两个好用的Xcode插件(提供下载链接)

iOS开发UI篇—推荐两个好用的Xcode插件(提供下载链接) 这里推荐两款好用的Xcode插件,并提供下载链接. 一.插件和使用如下: 1.两款插件 对项目中图片提供自动提示功能的插件:KSImageNamed-Xcode-master 提供快速创建自动注释:VVDocumenter-Xcode-master 2.使用介绍: (1)KSImageNamed-Xcode-master的使用 安装该插件后,会对文件中图片进行智能提示. (2)VVDocumenter-Xcode-master能提供

IOS 开发环境,证书和授权文件等详解

一.成员介绍 1.    Certification(证书) 证书是对电脑开发资格的认证,每个开发者帐号有一套,分为两种: 1)    Developer Certification(开发证书) 安装在电脑上提供权限:开发人员通过设备进行真机测试. 可以生成副本供多台电脑安装: 2)      Distribution Certification(发布证书) 安装在电脑上提供发布iOS程序的权限:开发人员可以制做测试版和发布版的程序. 不可生成副本,仅有配置该证书的电脑才可使用:(副本制做介绍在

iOS开发之保存照片到系统相册(Photo Album)

iOS开发之保存照片到系统相册(Photo Album) 保存照片到系统相册这个功能很多社交类的APP都有的,今天我们简单讲解一下,如何将图片保存到系统相册(Photo Album). 创建UIImageView 创建UIImageView是为了将照片展示出来,我们是要把UIImage保存到系统相册(Photo Album): #define SCREEN [UIScreen mainScreen].bounds.size self.image = [UIImage imageNamed:@"i

iOS开发网络篇—发送GET和POST请求(使用NSURLSession)

iOS开发网络篇—发送GET和POST请求(使用NSURLSession) 说明: 1)该文主要介绍如何使用NSURLSession来发送GET请求和POST请求 2)本文将不再讲解NSURLConnection的使用,如有需要了解NSURLConnection如何发送请求. 详细信息,请参考:http://www.cnblogs.com/wendingding/p/3813706.html 3)本文示例代码发送的请求均为http请求,已经对info.plist文件进行配置. 如何配置,请参考:

iOS开发中UIPopoverController的使用详解

这篇文章主要介绍了iOS开发中UIPopoverController的使用,代码基于传统的Objective-C,需要的朋友可以参考下 一.简单介绍 1.什么是UIPopoverController 是iPad开发中常见的一种控制器(在iPhone上不允许使用) 跟其他控制器不一样的是,它直接继承自NSObject,并非继承自UIViewController 它只占用部分屏幕空间来呈现信息,而且显示在屏幕的最前面 2.使用步骤 要想显示一个UIPopoverController,需要经过下列步骤

iOS开发——多线程OC篇&GCD实用总结

GCD实用总结 图片下载 注:iOS开发中常见GCD的实用也就这些了, 先来看看之前我们经常使用的方式: 1 static NSOperationQueue * queue; 2 3 - (IBAction)someClick:(id)sender { 4 self.indicator.hidden = NO; 5 [self.indicator startAnimating]; 6 queue = [[NSOperationQueue alloc] init]; 7 NSInvocationO