博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
iOS开发之检查更新
阅读量:6415 次
发布时间:2019-06-23

本文共 4185 字,大约阅读时间需要 13 分钟。

 

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

 

来源:

转载地址:http://hrbra.baihongyu.com/

你可能感兴趣的文章
Linux Centos 查询信息
查看>>
android adb命令
查看>>
python “双”稀疏矩阵转换为最小联通量“单”矩阵
查看>>
揭秘天猫双11背后:20万商家600万张海报,背后只有一个鹿班
查看>>
重置mysq root密码脚本
查看>>
我的友情链接
查看>>
MHA配置参数
查看>>
深入理解Lock
查看>>
vim的块选择
查看>>
HTML --块
查看>>
在DLL中获取主进程窗口句柄
查看>>
基于消息队列的双向通信
查看>>
一个不错的loading效果
查看>>
高中学渣逆袭入“大学”:如今月收入达五位数
查看>>
Debian允许root用户登录
查看>>
C++ - this指针
查看>>
Google Test and Google Mock Introduction
查看>>
linux的文件系统
查看>>
上云利器,K8S应用编排设计器之快到极致
查看>>
袋鼠云服务案例系列 | 从DB2到MySQL,某传统金融平台的互联网转型之路
查看>>