.h文件中

<UIAlertViewDelegate>

.m文件中

#import "SBJson.h"        //解析sbjson 数据

- (void)viewDidLoad
{
[super viewDidLoad]; ⋯⋯ [self checkVersion]; //检测升级 }
#pragma mark - 实现升级功能

//检测软件是否需要升级
-(void)checkVersion
{
NSString *newVersion;
NSURL *url = [NSURL URLWithString:@"http://itunes.apple.com/cn/lookup?id=692579125"]; //通过url获取数据
NSString *jsonResponseString = [NSString stringWithContentsOfURL:url encoding:NSUTF8StringEncoding error:nil];
NSLog(@"通过appStore获取的数据是:%@",jsonResponseString); //解析json数据为数据字典
NSDictionary *loginAuthenticationResponse = [self dictionaryFromJsonFormatOriginalData:jsonResponseString]; //从数据字典中检出版本号数据
NSArray *configData = [loginAuthenticationResponse valueForKey:@"results"];
for(id config in configData)
{
newVersion = [config valueForKey:@"version"];
} NSLog(@"通过appStore获取的版本号是:%@",newVersion); //获取本地软件的版本号
NSString *localVersion = [[[NSBundle mainBundle]infoDictionary] objectForKey:@"CFBundleVersion"]; NSString *msg = [NSString stringWithFormat:@"你当前的版本是V%@,发现新版本V%@,是否下载新版本?",localVersion,newVersion]; //对比发现的新版本和本地的版本
if ([newVersion floatValue] > [localVersion floatValue])
{
UIAlertView *createUserResponseAlert = [[UIAlertView alloc] initWithTitle:@"升级提示!" message:msg delegate:self cancelButtonTitle:@"下次再说" otherButtonTitles: @"现在升级", nil];
[createUserResponseAlert show];
[createUserResponseAlert release];
}
} //响应升级提示按钮
- (void)alertView:(UIAlertView *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
//如果选择“现在升级”
if (buttonIndex == )
{
//打开iTunes 方法一
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"https://itunes.apple.com/cn/app/wan-zhuan-quan-cheng/id692579125?mt=8"]]; /*
// 打开iTunes 方法二:此方法总是提示“无法连接到itunes”,不推荐使用
NSString *iTunesLink = @"itms-apps://phobos.apple.com/WebObjects/MZStore.woa/wa/viewSoftwareUpdate?id=692579125&mt=8";
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:iTunesLink]];
*/
}
} #pragma mark - 辅助方法:将json 格式的原始数据转解析成数据字典
//将json 格式的原始数据转解析成数据字典
-(NSMutableDictionary *)dictionaryFromJsonFormatOriginalData:(NSString *)str
{
SBJsonParser *sbJsonParser = [[SBJsonParser alloc]init];
NSError *error = nil; //添加autorelease 解决 内存泄漏问题
NSMutableDictionary *tempDictionary = [[[NSMutableDictionary alloc]initWithDictionary:[sbJsonParser objectWithString:str error:&error]]autorelease];
return tempDictionary;
}

参考:

//基于企业级证书的IOS应用打包升级功能介绍

http://blog.csdn.net/sbvfhp/article/details/10336715

//另一种代码实现思路

http://hi.baidu.com/wwssttt/item/7446105e3c98fa3933e0a9d5

//向appStore获取软件版本的代码,有步骤

http://blog.csdn.net/wave_1102/article/details/7463697

//向 appstore 查询已发布 APP 的信息--纯思路

http://hi.baidu.com/yanh105/item/7378a98ffca6a8804414cfa0

//官方帮助文档

http://www.apple.com/itunes/affiliates/resources/documentation/itunes-store-web-service-search-api.html

//如何改进iOS客户端的升级提醒功能

http://www.cocoachina.com/applenews/devnews/2013/0108/5495.html

//ios项目如何实现版本更新?

http://blog.csdn.net/mad1989/article/details/8130013

//解决向appStore 发送请求获取版本,没有返回信息的问题

http://www.cocoachina.com/ask/questions/show/56158

最新文章

  1. 中国CIO最关心的八大问题(下)
  2. HDU2896 病毒侵袭
  3. java中&quot;与&quot;和&quot;或&quot;
  4. Android Studio 0.4 + PhoneGap 3.3 开发环境的搭建
  5. poj 1845(等比数列前n项和及高速幂)
  6. 【BZOJ4327】JSOI2012 玄武密码 AC自动机
  7. Webservice WCF WebApi
  8. php取出数组中的最大值
  9. 将notepad++打造成java快速开发IDE
  10. strcmp函数
  11. winform程序压缩文件上传,服务器端asp.net mvc进行接收解压
  12. Linux清空文件内容
  13. C# string 字符串详解 恒定 驻留
  14. 例子:使用Grunt创建一个Node.js类库
  15. POJ1639顶点度限制最小生成树
  16. MFC框架仿真&lt;二&gt;
  17. golang sql.DB
  18. perl内置特殊变量查询
  19. Dijkstra【P2446】 [SDOI2010]大陆争霸
  20. 指数循环节&amp;欧拉降幂

热门文章

  1. jmock2.5 基本教程
  2. 学习python绘图
  3. 如何把自己的wordpress网站移到本地修改
  4. for循环练习--杨辉三角
  5. JAVA类课后练习
  6. Bad connection to FS. command aborted. exception: Call to chaoren/192.168.80.100:9000 failed on connection exception: java.net.ConnectException: Connection refused
  7. HDU 1028 HDU 1398 (母函数)
  8. SD卡分区查看(u-boot下)
  9. 容易错的try
  10. ?P&lt;username&gt;\w+