#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. 11g RAC日志体系(cluster,database,asm,scan日志,ADRCI工具的使用)

  2. oracle组件

    目前在用的四个oracle版本 Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - ProductionWith the Parti ...

  3. linux服务之svn

    架构:c/s 开发语言:python 服务器端:在linux平台下部署 客户端:分gui与cli两种操作界面 相关包: http://blog.sina.com.cn/s/blog_53b95aec0 ...

  4. unity,生成的mac版游戏切场景时卡死解法

    unity版本为5.1.1,在编辑器里运行没问题,build出的windows版运行也没问题,但build出的mac版在个别场景切换时会卡死,通过查看log(查看build版本log的方法参考:htt ...

  5. android数据存储之File

    android中使用File进行存储主要使用到OpenFileOutput和OpenFileInput两个方法,下面直接用一个例子来说明一下. (1)布局文件main.xml文件 <?xml v ...

  6. js正则及常用方法函数总结

    正则表达式作为一种匹配处理字符串的利器在很多语言中都得到了广泛实现和应用,web开发本质上是处理字符串(服务端接受请求处理后拼接字符串作为响应,这在早期的CGI编程中最明显,然后客户端解析字符串进行渲 ...

  7. J2EE分布式事务中的提交、回滚方法调用异常。

    这个是昨天上班的时候,写一个后台程序的调试程序时碰到的问题,和项目经理纠结了一天,最后搞定了.于是今天上班正好闲着,花了几乎一天的时间去网上找各种相关的资料.目前了解的内容如此: 根据使用的weblo ...

  8. Android 隐藏Fragment

    1.隐藏Fragment FragmentManager fManager = getFragmentManager(); fManager.beginTransaction() .setCustom ...

  9. ajax用户名案例(重点)

      要求:失去焦点时如下效果 主页代码 <body> 用户名:<input type="text" id="a" /><div i ...

  10. Hub, bridge, switch, router, gateway的区别

    这些概念性的东西,其实,有的区别不是很大,有的区别很大. Hub 就是一个重复转发器,就是从一个port接受到数据后,就会原样的向其他的所有端口发送刚才收到的数据.个人理解为是工作在物理层的东西.但是 ...