转载 -- iOS通过iTunes search检测版本更新,并提示用户更新!
来源:互联网 发布:ssh毕业设计2016源码 编辑:程序博客网 时间:2024/05/20 08:45
iOS通过iTunes search检测版本更新,并提示用户更新!
原文地址:http://blog.csdn.net/nong1209/article/details/7847346
如果我们要检测app版本的更新,那么我们必须获取当前运行app版本的版本信息和appstore 上发布的最新版本的信息。
当前运行版本信息可以通过info.plist文件中的bundle version中获取:
- NSDictionary *infoDic = [[NSBundle mainBundle] infoDictionary];
- CFShow(infoDic);
- NSString *appVersion = [infoDic objectForKey:@"CFBundleVersion"];
这样就获取到当前运行的app的版本了
要获取当前app store上的最新的版本,有两种方法,
一、在某特定的服务器上,发布和存储app最新的版本信息,需要的时候向该服务器请求查询。
二、从app store上查询,可以获取到app的作者,连接,版本等。官方相关文档
www.apple.com/itunes/affiliates/resources/documentation/itunes-store-web-service-search-api.htm
具体步骤如下:
1,用 POST 方式发送请求:
http://itunes.apple.com/search?term=你的应用程序名称&entity=software
更加精准的做法是根据 app 的 id 来查找:
http://itunes.apple.com/lookup?id=你的应用程序的ID
#define APP_URL http://itunes.apple.com/lookup?id=你的应用程序的ID
你的应用程序的ID 是 itunes connect里的 Apple ID
2,从获得的 response 数据中解析需要的数据。因为从 appstore 查询得到的信息是 JSON 格式的,所以需要经过解析。解析之后得到的原始数据就是如下这个样子的:
{
resultCount = 1;
results = (
{
artistId = 开发者 ID;
artistName = 开发者名称;
price = 0;
isGameCenterEnabled = 0;
kind = software;
languageCodesISO2A = (
EN
);
trackCensoredName = 审查名称;
trackContentRating = 评级;
trackId = 应用程序 ID;
trackName = 应用程序名称";
trackViewUrl = 应用程序介绍网址;
userRatingCount = 用户评级;
userRatingCountForCurrentVersion = 1;
version = 版本号;
wrapperType = software;
}
);
}
然后从中取得 results 数组即可,具体代码如下所示:
NSDictionary *jsonData = [dataPayload JSONValue];
NSArray *infoArray = [jsonData objectForKey:@"results"];
NSDictionary *releaseInfo = [infoArray objectAtIndex:0];
NSString *latestVersion = [releaseInfo objectForKey:@"version"];
NSString *trackViewUrl = [releaseInfo objectForKey:@"trackViewUrl"];
如果你拷贝 trackViewUrl 的实际地址,然后在浏览器中打开,就会打开你的应用程序在 appstore 中的介绍页面。当然我们也可以在代码中调用 safari 来打开它。
UIApplication *application = [UIApplication sharedApplication];
[application openURL:[NSURL URLWithString:trackViewUrl]];
- -(void)onCheckVersion:(NSString *)currentVersion
- {
- NSString *URL = APP_URL;
- NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
- [request setURL:[NSURL URLWithString:URL]];
- [request setHTTPMethod:@"POST"];
- NSHTTPURLResponse *urlResponse = nil;
- NSError *error = nil;
- NSData *recervedData = [NSURLConnection sendSynchronousRequest:request returningResponse:&urlResponse error:&error];
- NSString *results = [[NSString alloc] initWithBytes:[recervedData bytes] length:[recervedData length] encoding:NSUTF8StringEncoding];
- NSDictionary *dic = [results JSONValue];
- NSArray *infoArray = [dic objectForKey:@"results"];
- if ([infoArray count]) {
- NSDictionary *releaseInfo = [infoArray objectAtIndex:0];
- NSString *lastVersion = [releaseInfo objectForKey:@"version"];
- if (![lastVersion isEqualToString:currentVersion]) {
- trackViewURL = [releaseInfo objectForKey:@"trackVireUrl"];
- UIAlertView *alert = [[[UIAlertView alloc] initWithTitle:@"更新" message:@"有新的版本更新,是否前往更新?" delegate:self cancelButtonTitle:@"关闭" otherButtonTitles:@"更新", nil] autorelease];
- [alert show];
- }
- }
- }
参考博客:http://hi.baidu.com/yanh105/item/7378a98ffca6a8804414cfa0
- 转载 -- iOS通过iTunes search检测版本更新,并提示用户更新!
- iOS通过iTunes search检测版本更新,并提示用户更新!
- iOS通过iTunes search检测版本更新,并提示用户更新!
- iOS通过iTunes search检测版本更新,并提示用户更新!
- iOS通过iTunes search检测版本更新,并提示用户更新!
- iOS通过iTunes search检测版本更新,并提示用户更新!
- iOS通过iTunes search检测版本更新,并提示用户更新
- iOS通过iTunes search检测版本更新,并提示用户更新!
- iOS通过iTunes search检测版本更新,并提示用户更新!
- iOS通过iTunes search检测版本更新,并提示用户更新!
- iOS通过iTunes search检测版本更新,并提示用户更新!
- iOS通过iTunes search检测版本更新,并提示用户更新!
- iOS通过iTunes search检测版本更新,并提示用户更新!
- iOS通过iTunes search检测版本更新,并提示用户更新!
- iOS通过iTunes search检测版本更新,并提示用户更新!
- iOS通过iTunes search检测版本更新,并提示用户更新!
- iOS通过iTunes search检测版本更新,并提示用户更新
- iOS通过iTunes search检测版本更新,并提示用户更新!
- java 找出一个字符在 一个字符串中的位置
- 手机尾号 30年的改革开放,给中国带来了翻天覆地的变化。2011全年中国手机产量约为11.72亿部。手机已经成为百姓的基本日用品! 给手机选个好听又好记的号码可能是许多人的心愿。
- Ubuntu 12.04中文输入法的安装
- 网上动态新闻抓取网址
- Lucene中的中英文stop--word
- 转载 -- iOS通过iTunes search检测版本更新,并提示用户更新!
- 转载 -- IOS中Json解析的四种方法
- struts2 自定义类型转换器
- 战友,你的国防服役章,送给了谁?
- 第二届华中区程序设计邀请赛暨武汉大学第十一届校赛 网络预选赛 解题报告
- mysql不允许从远程登陆
- 入伍的抉择反思审问
- ZOJ 3551 Bloodsucker 概率DP
- 巴巴运动网技术点和功能