直接上代碼:
-
-
-
-
-(void)checkVersion
-
{
-
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"http://itunes.apple.com/cn/lookup?id=%i",iFeverAPPID]];
-
ASIHTTPRequest *request = [[ASIHTTPRequest alloc]initWithURL:url];
-
[request setUseCookiePersistence:YES];
-
[request setDelegate: self];
-
[request setDidFailSelector:@selector(getVersionRequestFailed:)];
-
[request setDidFinishSelector:@selector(getVersionRequestSuccess:)];
-
[request startAsynchronous];
-
}
-
-
-(void)getVersionRequestFailed:(ASIHTTPRequest *)request1
-
{
-
NSLog(@"從AppStore獲取版本信息失敗!!");
-
}
-
-
-(void)getVersionRequestSuccess:(ASIHTTPRequest *)request1
-
{
-
NSString *newVersion;
-
NSData *responseData = [request1 responseData];
-
NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:responseData options:NSJSONReadingAllowFragments error:nil];
-
NSArray *resultArray = [dic objectForKey:@"results"];
-
for (id config in resultArray) {
-
newVersion = [config valueForKey:@"version"];
-
}
-
if (newVersion) {
-
NSLog(@"通過AppStore獲取的版本號是:%@",newVersion);
-
}
-
-
NSString *localVersion = [[[NSBundle mainBundle]infoDictionary]objectForKey:@"CFBundleVersion"];
-
NSString *msg = [NSString stringWithFormat:@"你當前的版本是V%@,發現新版本V%@,是否下載新版本?",localVersion,newVersion];
-
if ([newVersion floatValue] > [localVersion floatValue]) {
-
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"升級提示!" message:msg delegate:self cancelButtonTitle:@"下次再說" otherButtonTitles:@"現在升級", nil nil];
-
alert.tag = kVersionNeedUpdateAlertTag;
-
[alert show];
-
}
-
}
-
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
-
{
-
if (alertView.tag == kVersionNeedUpdateAlertTag) {
-
-
if (buttonIndex == 1) {
-
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"https://itunes.apple.com/cn/app/wan-zhuan-quan-cheng/id%i?mt=8",iFeverAPPID]];
-
[[UIApplication sharedApplication]openURL:url];
-
-
-
-
-
-
-
}
-
}
-
}
如果想知道網絡請求AppStore時返回的信息可以打開這個鏈接:http://itunes.apple.com/cn/lookup?id=465039730
參考博文:
//基於企業級證書的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