app升級策略

直接上代碼:
[objc] view plain copy
  1. /** 
  2.  *  檢測軟件是否需要升級 
  3.  */  
  4. -(void)checkVersion  
  5. {  
  6.     NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"http://itunes.apple.com/cn/lookup?id=%i",iFeverAPPID]];  
  7.     ASIHTTPRequest *request = [[ASIHTTPRequest alloc]initWithURL:url];  
  8.     [request setUseCookiePersistence:YES];  
  9.     [request setDelegate: self];  
  10.     [request setDidFailSelector:@selector(getVersionRequestFailed:)];  
  11.     [request setDidFinishSelector:@selector(getVersionRequestSuccess:)];  
  12.     [request startAsynchronous];//開始異步請求  
  13. }  
  14.   
  15. -(void)getVersionRequestFailed:(ASIHTTPRequest *)request1  
  16. {  
  17.     NSLog(@"從AppStore獲取版本信息失敗!!");  
  18. }  
  19.   
  20. -(void)getVersionRequestSuccess:(ASIHTTPRequest *)request1  
  21. {  
  22.     NSString *newVersion;  
  23.     NSData *responseData = [request1 responseData];  
  24.     NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:responseData options:NSJSONReadingAllowFragments error:nil];  
  25.     NSArray *resultArray = [dic objectForKey:@"results"];  
  26.     for (id config in resultArray) {  
  27.         newVersion = [config valueForKey:@"version"];  
  28.     }  
  29.     if (newVersion) {  
  30.         NSLog(@"通過AppStore獲取的版本號是:%@",newVersion);  
  31.     }  
  32.     //獲取本地版本號  
  33.     NSString *localVersion = [[[NSBundle mainBundle]infoDictionary]objectForKey:@"CFBundleVersion"];  
  34.     NSString *msg = [NSString stringWithFormat:@"你當前的版本是V%@,發現新版本V%@,是否下載新版本?",localVersion,newVersion];  
  35.     if ([newVersion floatValue] > [localVersion floatValue]) {  
  36.         UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"升級提示!" message:msg delegate:self cancelButtonTitle:@"下次再說" otherButtonTitles:@"現在升級", nil nil];  
  37.         alert.tag = kVersionNeedUpdateAlertTag;  
  38.         [alert show];  
  39.     }  
  40. }  

[objc] view plain copy
  1. -(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex  
  2. {  
  3.     if (alertView.tag == kVersionNeedUpdateAlertTag) {  
  4.         //軟件需要更新提醒  
  5.         if (buttonIndex == 1) {  
  6.             NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"https://itunes.apple.com/cn/app/wan-zhuan-quan-cheng/id%i?mt=8",iFeverAPPID]];  
  7.             [[UIApplication sharedApplication]openURL:url];  
  8.             /* 
  9.              // 打開iTunes 方法二:此方法總是提示“無法連接到itunes”,不推薦使用 
  10.              NSString *iTunesLink = @"itms-apps://phobos.apple.com/WebObjects/MZStore.woa/wa/viewSoftwareUpdate?id=%i&mt=8"; 
  11.              NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"itms-apps://phobos.apple.com/WebObjects/MZStore.woa/wa/viewSoftwareUpdate?id=%i&mt=8",iFeverAPPID]]; 
  12.              [[UIApplication sharedApplication] openURL:url]; 
  13.              */  
  14.         }  
  15.     }  
  16. }  


如果想知道網絡請求AppStore時返回的信息可以打開這個鏈接:http://itunes.apple.com/cn/lookup?id=465039730

參考博文:

iOS appStore中的應用 實現升級功能  http://www.cnblogs.com/ygm900/p/3334586.html


//基於企業級證書的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

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章