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 ...
随机推荐
- poj1125&zoj1082Stockbroker Grapevine(Floyd算法)
Stockbroker Grapevine Time Limit: 1000MS Memory Limit: 10000K Description Stockbrokers are known to ...
- matlab ASCII 格式导入
matlab ASCII 格式导入 可以用fprintf函数,来代替save函数啊比如现在我有一个变量a=[0.1223 345.4544]如果我想保存它的话,可以用下面的程序:fid = fopen ...
- 异机恢复perform restores
Restoring and Recovering the database on a new host 第一台机器上mount模式下做全备 new host: 1.配置oracle_sid和之 ...
- 内存流和null字节
#include <stdio.h> #include <string.h> int main() { ]={}; FILE* fp = fmemopen(buf,," ...
- Maxwell’s Equations
A=cos(pi*x-pi/2)i+sin(pi*x)j 正电荷形成的电场 负电荷形成的电场 正负电荷形成的电场 无限长导线上均匀分布的正电荷 电场 均匀分布电荷的平面 电场 电荷均匀分布的球面形 ...
- java常用方法总结
最近打算换工作,还是需要补一下面试的基础知识,写了一些面试中可能会用到的常用算法.方法,以便复习 //99乘法表 /** * 1*1 * 1*1 1*2 * 1*1 1*2 1*3 * …… * */ ...
- java使用HttpClient传输json格式的参数
最近的一个接口项目,传的参数要求是json,需要特殊处理一下. 重点是这两句话: httpPost.setHeader("Content-Type", "applicat ...
- 算法最坏,平均和最佳情况(Worst, Average and Best Cases)-------geeksforgeeks 翻译
最坏,平均和最佳运行时间(Worst, Average and Best Cases) 在上一篇文章中,我们讨论到了渐进分析可以解决分析算法的问题,那么在这一篇中,我们用线性搜索来举例说明一下如何用渐 ...
- codeforces 477A A. Dreamoon and Sums(数学)
题目链接: A. Dreamoon and Sums time limit per test 1.5 seconds memory limit per test 256 megabytes input ...
- 在A*寻路中使用二叉堆
接上篇:A*寻路初探 GameDev.net 在A*寻路中使用二叉堆 作者:Patrick Lester(2003年4月11日更新) 译者:Panic 2005年3月28日 译者序 这一篇文章,是&q ...