.h文件中html
<UIAlertViewDelegate>ios
.m文件中web
#import "SBJson.h" //解析sbjson 數據json
- (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 == 1) { //打開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; }
參考:api
//基於企業級證書的IOS應用打包升級功能介紹app
http://blog.csdn.net/sbvfhp/article/details/10336715url
//另外一種代碼實現思路spa
http://hi.baidu.com/wwssttt/item/7446105e3c98fa3933e0a9d5.net
//向appStore獲取軟件版本的代碼,有步驟code
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