iOS 版本更新检查
#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 版本更新检查的更多相关文章
- iOS 版本更新(强制更新)检测问题
iOS 版本更新(强制更新)检测问题 通常iOS系统中是默认设置再wifi状态,且网络状况良好下自己更新应用的. 但是如果用户设置了不自动更新,但是我们的APP出现重要的版本,一定需要用户更新的情况下 ...
- iOS 版本更新迭代
开发中我们可能会遇到这样的需求,当AppStore中有新版本迭代更新,在用户点开APP的时候弹框提醒客户去AppStore更新APP.这里面就有个关键点,判断当前APP与AppStore中的版本高低, ...
- ios 实现版本更新检查
注:这里网络请求用的是第三方框架:SVHTTPRequest /* 第一步: 根据应用名称搜索应用,然后根据应用绑定的ID在结果中筛选出我们要找的应用,并取出应用的AppID */ - (void)g ...
- iOS版本更新的App提交审核发布流程
http://www.2cto.com/kf/201502/378698.html 版本更新的App和新App的发布提交流程略有不同,新的App需要在开发者账号里准备发布证书,添加App的id,关联描 ...
- iOS版本更新的App提交审核流程
App的版本更新估计是在所难免的了!更新App和新的App发布有何不同了?今天我们一起来看看吧!在发布App的时候我们需要通过开发者帐号——(申请)——>发布证书(需要钥匙串对证书签名也叫加密( ...
- iOS7 中的新加入的下载类NSURLSession(随ios版本更新而更新)
想详细的了解网络下载的相关知识,要仔细阅读URL Loading System Programming Guide 这里有篇好文章(http://www.shinobicontrols.com/blo ...
- iOS版本更新在APP中直接访问AppStore
1.导入框架 #import <StoreKit/StoreKit.h> 2.添加代理 <SKStoreProductViewControllerDelegate> 3.设置跳 ...
- ios版本更新总结
更新思路,获取APP Store 版本号与项目本地版本号对比,如果本地低于商店版本号,就提示用户更新(说明:在上架项目时请保持本地和商店版本号一致,避免检测更新问题被拒) 1.获取商店版本号,代码如下 ...
- ios 版本更新提示-硬更新/软更新
实现: 强制更新:每次弹框 非强制更新:一天提示一次 代码如下: 步骤一: 将检测更新写到APPDelegate的applicationDidBecomeActive中 步骤二: 检测是否需要更新 步 ...
随机推荐
- javascript实现kruskal算法
<script> //图的构建 function vnode() { this.visited = 0; this.vertex = 0; this.arcs = new Array(); ...
- java performance
http://www.oracle.com/technetwork/java/performance-138178.html# http://www.oracle.com/technetwork/ja ...
- JavaScript-闭包注意事项
闭包允许内层函数引用父函数中的变量,但是该变量是最终值
- Discuz 3.X 整合 CAS 的方法
1,新建 CasClient.php <?php include_once (dirname ( __FILE__ ) . '/CasClientConfig.php'); // 注意这个 in ...
- max plugin wizard,project creation faild解法
两点需要注意: 1,要将maxsdk的3dsmaxPluginWizard文件夹设为只读. 2,要将3dsmaxPluginWizard.vsz中的"Wizard="设置为正确的v ...
- webpack需要全局安装,才能使用webpack命令
webpack全局安装,具体项目中才能使用webpack命令: npm install webpack -g
- javascript中单体模式的实现
单体模式作为一种软件开发模式在众多面向对象语言中得到了广泛的使用,在javascript中,单体模式也是使用非常广泛的,但是由于javascript语言拥有其独特的面向对象方式,导致其和一些传统面向对 ...
- Keepalived 双机web服务宕机检测切换系统软件
简介 Keepalived的作用是检测web服务器的状态,如果有一台web服务器死机,或工作出现故障,Keepalived将检测到,并将有故障的web服务器从系统中剔除,当web服务器工作正常后Kee ...
- 国外HTML网站模版(卖成品模版)
有非常多的模版,遗憾的是都要钱 http://themeforest.net/search?utf8=%E2%9C%93&term=&view=list&sort=sales& ...
- 【shell】条件判断式
条件判断式的表示格式: 文件判断式: [root@andon ~]# [ -e /root/1 ] && echo yes || echo no #注意[]里面的空格,第一个命令为真打 ...