IOS判断app在appstore是否有可用的更新
iTunes可以提供app的版本信息,主要通过appid获取,如 http://itunes.apple.com/lookup?id=946449501,使用时只需要到iTunes查找自己的appid,修改成自己的appid即可
使用HTTP模式读取此链接可以获取app信息的json字符串
贴出部分代码
-(void)checkVersion
{
ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:[NSURL URLWithString:strURL]];//strURL为你的appid地址
[request setRequestMethod:@"POST"];
[request setDelegate:self];
[request startAsynchronous];
} -(void)requestFinished:(ASIHTTPRequest *)request
{
NSString *recStr = [[NSString alloc] initWithData:request.responseData encoding:NSUTF8StringEncoding];
recStr = [recStr stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];//返回的字符串有前面有很多换行符,需要去除一下
NSDictionary *resultDic = [JSONHelper DeserializerDictionary:recStr];//jsonhelper是我封装的json解析类,你可以使用自己方式解析 NSArray *infoArray = [resultDic objectForKey:@"results"];
if (infoArray.count > 0) { NSDictionary* releaseInfo =[infoArray objectAtIndex:0];
NSString* appStoreVersion = [releaseInfo objectForKey:@"version"];
NSDictionary *infoDic = [[NSBundle mainBundle] infoDictionary];
NSString *currentVersion = [infoDic objectForKey:@"CFBundleShortVersionString"]; NSArray *curVerArr = [currentVersion componentsSeparatedByString:@"."];
NSArray *appstoreVerArr = [appStoreVersion componentsSeparatedByString:@"."];
BOOL needUpdate = NO;
//比较版本号大小
int maxv = (int)MAX(curVerArr.count, appstoreVerArr.count);
int cver = 0;
int aver = 0;
for (int i = 0; i < maxv; i++) {
if (appstoreVerArr.count > i) {
aver = [NSString stringWithFormat:@"%@",appstoreVerArr[i]].intValue;
}
else{
aver = 0;
}
if (curVerArr.count > i) {
cver = [NSString stringWithFormat:@"%@",curVerArr[i]].intValue;
}
else{
cver = 0;
}
if (aver > cver) {
needUpdate = YES;
break;
}
} //如果有可用的更新
if (needUpdate){ trackViewURL = [[NSString alloc] initWithString:[releaseInfo objectForKey:@"trackViewUrl"]];//trackViewURL临时变量存储app下载地址,可以让app跳转到appstore
UIAlertView* alertview =[[UIAlertView alloc] initWithTitle:@"版本升级" message:[NSString stringWithFormat:@"发现有新版本,是否升级?"] delegate:self cancelButtonTitle:@"暂不升级" otherButtonTitles:@"马上升级", nil];
[alertview show]; } }
} - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
if (buttonIndex == 1){
UIApplication *application = [UIApplication sharedApplication];
[application openURL:[NSURL URLWithString:trackViewURL]];
}
}
IOS判断app在appstore是否有可用的更新的更多相关文章
- andorid IOS 判断APP下载
<?phpif(strpos($_SERVER['HTTP_USER_AGENT'], 'iPhone')||strpos($_SERVER['HTTP_USER_AGENT'], 'iPad' ...
- iOS 判断App启动方式
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launc ...
- ios 判断app程序第一次启动方法
if(![[NSUserDefaults standardUserDefaults] boolForKey:@"firstStart"]){ [[NSUserDefaults st ...
- ios的app,有新版本时必须先更新。
现在没时间整理,先把代码贴出来,以后再做详细的思路整理. 1 在AppController.mm的didFinishLaunchingWithOptions方法里面获取本地应用版本信息,保存起来. / ...
- 最新Xcode7.x环境下上架iOS App到AppStore 完整流程
最新Xcode7.x环境下上架iOS App到AppStore 流程 part 1 前言部分 之前App要上架遇到些问题到网上搜上架教程发现都是一些老的版本的教程 ,目前iTunesConnect ...
- iOS 从0到1搭建高可用App框架
iOS 从0到1搭建高可用App框架 最近在搭建新项目的iOS框架,一直在思考如何才能搭建出高可用App框架,能否避免后期因为代码质量问题的重构.以前接手过许多“烂代码”,架构松散,底层混乱,缺少规范 ...
- (转))iOS App上架AppStore 会遇到的坑
iOS App上架AppStore 会遇到的坑 前言:非原创 文章摘自:http://zhuanlan.zhihu.com/100000PM/20010725 相信大家一定非常「深恶痛疾」AppS ...
- windows如何上传ios app到appstore
我们在hbuilderx这些开发工具打包好ios app后,需要将这个app提交appstore才能让用户下载安装. 上传IOS APP主要是通过苹果开发者中心来上传,然后借助香蕉云编上传工具来上传就 ...
- 教程Xcode 下编译发布与提交App到AppStore
The proplem of Prepare for Upload for App store upload Application App store 增加新应用的步骤. 1. 访问iTunesCo ...
随机推荐
- c++基础回顾
#include <iostream> #include <vector> #include <string> int main(int argc, const c ...
- POI教程之第一讲:创建新工作簿, Sheet 页,创建单元格
第一讲 Poi 简介 Apache POI 是Apache 软件基金会的开放源码函数库,Poi提供API给java程序对Microsoft Office格式档案读和写的功能. 1.创建新工作簿,并给工 ...
- linux基本命令学习笔记
这个几天在研究linux的常用基本命令.以下是此时间内的幻灯片截图笔记,在这里留个脚印. linux 常用命令 1,命令的基本格式 2,文件处理命令 3,文件搜索命令 4,帮助命令 5,压缩解压缩命令 ...
- mysql中count(),group by使用
count()统计表中或数组中记录 count(*)返回检索行的数目,且不论其值中是否包含NULL count(column_name)返回的是对列中column_name不为NULL的行的统计 例如 ...
- mysql存储过程procedure
传送门 http://www.blogjava.net/sxyx2008/archive/2009/11/24/303497.html ) ); DROP PROCEDURE IF EXISTS ju ...
- 基于jython操作hbase
一.前言 关于jython介绍,直接上官网www.jython.org,可以得到详细资料,这里只介绍一下jython操作hbase的一些方法,本质上和用java操作hbase差不多,只不过语法换成了p ...
- MSDE简介
MSDE的全程是Microsoft SQL Server Desktop Engine,它是一个基于 SQL Server 核心技术构建的数据引擎.MSDE 2000 支持单处理器和双处理器,是面向小 ...
- cri-o 与 cni的集成分析
// 创建pod时,network的设置 1.// cri-o/server/sandbox.go // RunPodSandbox creates and runs a pod-level sand ...
- 如何解决python中urlopen超时问题
看代码: 利用urlopen中的超时参数设立一个循环 while True: try: page = urllib.request.urlopen(url, timeout=3) break exce ...
- 八皇后,回溯与递归(Python实现)
八皇后问题是十九世纪著名的数学家高斯1850年提出 .以下为python语句的八皇后代码,摘自<Python基础教程>,代码相对于其他语言,来得短小且一次性可以打印出92种结果.同时可以扩 ...