iOS迭代版本 (转)
来源:互联网 发布:少儿编程教育培训 编辑:程序博客网 时间:2024/05/18 00:29
当前运行版本信息可以通过info.plist文件中的bundle version中获取:[cpp] view plaincopyNSDictionary *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 ID2,从获得的 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{ NSDictionary *infoDic = [[NSBundle mainBundle] infoDictionary]; //CFShow((__bridge CFTypeRef)(infoDic)); NSString *currentVersion = [infoDic objectForKey:@"CFBundleVersion"]; NSString *URL = @"http://itunes.apple.com/lookup?id=你的应用程序的ID"; 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:&urlResponseerror:&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]; alert.tag = 10000; [alert show]; } else { UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"更新" message:@"此版本为最新版本"delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil]; alert.tag = 10001; [alert show]; } }}- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{ if (alertView.tag==10000) { if (buttonIndex==1) { NSURL *url = [NSURL URLWithString:@"https://itunes.apple.com"]; [[UIApplication sharedApplication]openURL:url]; } }}
0 0
- iOS迭代版本 (转)
- iOS版本迭代
- iOS 版本迭代 App升级安装 CoreData数据库升级
- 公司IOS接手该如何迭代app版本
- 转的 侵立删 java版本迭代
- 版本迭代
- 版本更新迭代
- Android版本迭代
- 版本迭代
- iOS app版本迭代(iOS中app在iTunes中更新版本流程)
- iOS app版本迭代(iOS中app在iTunes中更新版本流程)
- iOS app版本迭代(iOS中app在iTunes中更新版本流程)
- iOS app版本迭代(iOS中app在iTunes中更新版本流程)
- iOS app版本迭代(iOS中app在iTunes中更新版本流程)
- iOS--开发技巧--iOS app 上架(2016年10月底)以及版本迭代上架
- CoreData的版本迭代
- 提交APPStore版本迭代
- kafka 版本迭代递进
- Effective C++ 第3条:尽可能使用const
- ios developer tiny share-20160929
- DrawRect
- Oracle replace
- MyBatis逆向工程
- iOS迭代版本 (转)
- 单例模式
- 第一章:我的java学习之路
- ERROR 1366 (HY000): Incorrect string value: '\xC2\xEC\xD2\xCF\xD2\xB2...' for column 'title' at row
- Requestlayout,onlayout,onDraw,DrawChild区别与联系
- 关于人工智能的幻想---差不多有结果了
- Android事件分发,事件拦截,事件处理总结
- 深入block
- Android WebView 文本框获取焦点后自动放大有关问题