#pragma mark ----------------------------------

#pragma mark -- 检测版本更新

-(void)onCheckVersion

{

NSDictionary *infoDic = [[NSBundlemainBundle] infoDictionary];

NSString *currentVersion = [infoDic objectForKey:@"CFBundleShortVersionString"];//CFBundleVersion

NSString *URL = @"http://itunes.apple.com/lookup?id=你的appId";

NSMutableURLRequest *request = [[NSMutableURLRequestalloc] init];

[request setURL:[NSURL URLWithString:URL]];

[request setHTTPMethod:@"POST"];

[NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue currentQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) {

if (data == nil) {

return ;

}

NSDictionary *dic = [NSJSONSerializationJSONObjectWithData:data options:NSJSONReadingMutableContainerserror:nil];

NSArray *infoArray = [dic objectForKey:@"results"];

if ([infoArray count]) {

NSDictionary *releaseInfo = [infoArray objectAtIndex:0];

NSString *lastVersion = [releaseInfo objectForKey:@"version"];

//测试数据

//        currentVersion = @"1.1";

//        lastVersion = @"1.1.1";

//版本号处理并比较大小

NSMutableArray *lastVersionArr = [NSMutableArray arrayWithArray:[lastVersion componentsSeparatedByString:@"."]];

NSMutableArray *currentVersionArr = [NSMutableArray arrayWithArray:[currentVersion componentsSeparatedByString:@"."]];

BOOL haveNewVersion = NO;

//比较数组长度 不相等则 补零至相等

if (lastVersionArr.count > currentVersionArr.count) {

for (int i = 0 ; i < lastVersionArr.count - currentVersionArr.count; ++i) {

[currentVersionArr addObject:@"0"];

}

}else if (lastVersionArr.count < currentVersionArr.count){

for (int i = 0 ; i < currentVersionArr.count - lastVersionArr.count; ++i) {

[lastVersionArr addObject:@"0"];

}

}

//比较大小

for (int i = 0 ; i < currentVersionArr.count; ++i) {

if ([lastVersionArr[i] integerValue] > [currentVersionArr[i] integerValue]) {

haveNewVersion = YES;

[SettingsManager shareInstance].hasNewVersion = YES;

break;

}else if ([lastVersionArr[i] integerValue] < [currentVersionArr[i] integerValue])

{

haveNewVersion = NO;

[SettingsManager shareInstance].hasNewVersion = NO;

break;

}

}

if (haveNewVersion) {

UIAlertView *alert = [[UIAlertViewalloc] initWithTitle:NSLocalizedString(@"更新", nil) message:[releaseInfo  objectForKey:@"releaseNotes"] delegate:selfcancelButtonTitle:NSLocalizedString(@"取消", nil) otherButtonTitles:NSLocalizedString(@"前往更新", nil), nil];

alert.tag = 10000;

[alert show];

}

}

}];

}

#pragma mark - AertView delegate

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex

{

if (alertView.tag == 10000) {

if (buttonIndex == 1) {

[[UIApplicationsharedApplication] openURL:[NSURLURLWithString:@"你的App下载地址"]];

}

}

}

iOS 版本更新检查的更多相关文章

  1. iOS 版本更新(强制更新)检测问题

    iOS 版本更新(强制更新)检测问题 通常iOS系统中是默认设置再wifi状态,且网络状况良好下自己更新应用的. 但是如果用户设置了不自动更新,但是我们的APP出现重要的版本,一定需要用户更新的情况下 ...

  2. iOS 版本更新迭代

    开发中我们可能会遇到这样的需求,当AppStore中有新版本迭代更新,在用户点开APP的时候弹框提醒客户去AppStore更新APP.这里面就有个关键点,判断当前APP与AppStore中的版本高低, ...

  3. ios 实现版本更新检查

    注:这里网络请求用的是第三方框架:SVHTTPRequest /* 第一步: 根据应用名称搜索应用,然后根据应用绑定的ID在结果中筛选出我们要找的应用,并取出应用的AppID */ - (void)g ...

  4. iOS版本更新的App提交审核发布流程

    http://www.2cto.com/kf/201502/378698.html 版本更新的App和新App的发布提交流程略有不同,新的App需要在开发者账号里准备发布证书,添加App的id,关联描 ...

  5. iOS版本更新的App提交审核流程

    App的版本更新估计是在所难免的了!更新App和新的App发布有何不同了?今天我们一起来看看吧!在发布App的时候我们需要通过开发者帐号——(申请)——>发布证书(需要钥匙串对证书签名也叫加密( ...

  6. iOS7 中的新加入的下载类NSURLSession(随ios版本更新而更新)

    想详细的了解网络下载的相关知识,要仔细阅读URL Loading System Programming Guide 这里有篇好文章(http://www.shinobicontrols.com/blo ...

  7. iOS版本更新在APP中直接访问AppStore

    1.导入框架 #import <StoreKit/StoreKit.h> 2.添加代理 <SKStoreProductViewControllerDelegate> 3.设置跳 ...

  8. ios版本更新总结

    更新思路,获取APP Store 版本号与项目本地版本号对比,如果本地低于商店版本号,就提示用户更新(说明:在上架项目时请保持本地和商店版本号一致,避免检测更新问题被拒) 1.获取商店版本号,代码如下 ...

  9. ios 版本更新提示-硬更新/软更新

    实现: 强制更新:每次弹框 非强制更新:一天提示一次 代码如下: 步骤一: 将检测更新写到APPDelegate的applicationDidBecomeActive中 步骤二: 检测是否需要更新 步 ...

随机推荐

  1. c程序代码优化的一些方法

    我认为一个好的用于科学计算的程序代码应该:算法漂亮精妙,程序简洁易懂,运算快速,节省内存.这里有的地方是矛盾的,比如简洁vs易懂,时间vs空间,找个平衡吧.目前来看时间要比空间宝贵一些.写程序分几步: ...

  2. Python-描述符

    Python中包含了许多内建的语言特性,它们使得代码简洁且易于理解.这些特性包括列表/集合/字典推导式,属性(property).以及装饰器(decorator).对于大部分特性来说,这些“中级”的语 ...

  3. JavaScript的事件绑定及深入

     事件绑定分为两种:一种是传统事件绑定(内联模型,脚本模型),一种是现代事件绑定 (DOM2 级模型).现代事件绑定在传统绑定上提供了更强大更方便的功能. 一.传统事件绑定的问题传统事件绑定有内联模型 ...

  4. Unity3d 根据重力自动翻转

    玩游戏时,经常有这样的体验.我正常是左横屏,手机翻转过来为右横屏,游戏界面也随着翻转为右横屏. Unity3D引擎,不需要写任何代码,只需要 Player Setting 设置即可: 如图所示:

  5. HOCON 了解

    Spec This is an informal spec, but hopefully it's clear. Goals / Background The primary goal is: kee ...

  6. 使用git pull文件时和本地文件冲突怎么办?

    同事在使用git pull代码时,经常会碰到有冲突的情况,提示如下信息: error: Your local changes to 'c/environ.c' would be overwritten ...

  7. jquery显示隐藏toggle

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  8. MySQL中Group By,distinct使用注意事项

    mysql> select * from test; +----+-------+------+-------+ | id | name | age | class | +----+------ ...

  9. RMAN备份与恢复之数据文件

    备份数据文件,模拟磁盘损坏时,还原恢复数据文件. 首先,查询数据文件序号,备份数据文件,可根据数据文件序号指定备份的数据文件. SQL SQL> select file_name,file_id ...

  10. 计算阶乘n!末尾0的个数

    一.问题描述 给定一个正整数n,请计算n的阶乘n!末尾所含有“0”的个数.例如: 5!=120,其末尾所含有的“0”的个数为1: 10!= 3628800,其末尾所含有的“0”的个数为2: 20!= ...