分享

IOS 判断应用版本和升级提示

 没原创_去搜索 2015-07-27
http://blog.csdn.net/hengshujiyi/article/details/21171991


原文地址:http://blog.csdn.net/jslsblog/article/details/9932767


ios中应用的版本判断有两种方法:

1.将你的应用版本号同步在你自己的服务器上,打开程序后去自己的服务器获取版本号和手机上的应用版本号做比较,然后去appstore升级

2.通过url获取appstore上的最新版本信息,然后和手机上的程序版本号做比较,判断是否升级。

最常用的就是方法2,下面讲讲方法2的实现过程。

第一步是去获取appstore上你的应用的版本信息,需要用到的url    #define APP_URL    @"http://itunes.apple.com/lookup?id=662004496"

(替换id即可),我看网上很多的例子都是同步获取信息,这样会阻塞主线程,我还是觉得异步的比较好。


  1. -(void)checkVersion:(NSString* )appurl  
  2. {  
  3.     ASIFormDataRequest* request=[ASIFormDataRequest requestWithURL:[NSURL URLWithString:appurl]];  
  4.     [request setRequestMethod:@"POST"];  
  5.     [request setDelegate:self];  
  6.     [request startAsynchronous];  
  7.   
  8. }  

返回结果是需要使用json解析

  1. - (void)requestFinished:(ASIHTTPRequest *)request  
  2. {  
  3.     NSDictionary* resultDic=[request.responseData JSONValue];  
  4.     NSArray* infoArray = [resultDic objectForKey:@"results"];  
  5.     if (infoArray.count>0) {  
  6.         NSDictionary* releaseInfo =[infoArray objectAtIndex:0];  
  7.         NSString* appStoreVersion = [releaseInfo objectForKey:@"version"];  
  8.         NSDictionary *infoDic = [[NSBundle mainBundle] infoDictionary];  
  9.         NSString *currentVersion = [infoDic objectForKey:@"CFBundleShortVersionString"];  
  10.         if (![appStoreVersion isEqualToString:currentVersion])  
  11.         {  
  12.             trackViewURL = [[NSString alloc] initWithString:[releaseInfo objectForKey:@"trackViewUrl"]];  
  13.             NSString* msg =[releaseInfo objectForKey:@"releaseNotes"];  
  14.             UIAlertView* alertview =[[UIAlertView alloc] initWithTitle:@"版本升级" message:[NSString stringWithFormat:@"%@%@%@", @"新版本特性:",msg, @"\n是否升级?"] delegate:self cancelButtonTitle:@"稍后升级" otherButtonTitles:@"马上升级", nil];  
  15.             [alertview show];  
  16.         }  
  17.       
  18.     }  
  19. }  

这里要讲讲返回的json数据,aapple返回的数据有很多,你看情况选择你需要的数据,一般需要的一个是version,一个是应用新特性releaseNotes,还有一个就是跳转地址 trackViewUrl

    artistId = 
    artistName = 
    artistViewUrl = 
    artworkUrl100 = 
    artworkUrl512 = 
    artworkUrl60 =
    bundleId = 
    contentAdvisoryRating =
    currency = 
    description =
    features =   
    fileSizeBytes = 
    formattedPrice = 
    genreIds =    
    genres =    
    ipadScreenshotUrls =   
    isGameCenterEnabled =
    kind = 
    languageCodesISO2A =   
    price = 0;
    primaryGenreId = 6017;
    primaryGenreName = 
    releaseDate = "2013-08-07T07:03:16Z";
    releaseNotes = "1\U3001\U6dfb\U52a0QQ\U8054\U7cfb\U529f\U80fd\n2\U3001\U8bfe\U7a0b\U81ea\U52a8\U64ad\U653e\U65f6\U6e10\U9690\U8fc7\U5ea6\Uff0c\U89c6\U89c9\U6548\U679c\U66f4\U597d\n3\U3001\U4e13\U9898\U6392\U7248\U91cd\U65b0\U8bbe\U8ba1\Uff0c\U4f7f\U4e4b\U66f4\U591a\U7684\U663e\U793a\U4e13\U9898\U4ecb\U7ecd\n4\U3001\U8f6e\U64ad\U56fe\U7247\U52a0\U70b9\U6307\U793a\n5\U3001\U5b66\U9662\U4ecb\U7ecd\U53d8\U6210\U5bcc\U6587\U672c\Uff0c\U53ef\U4ee5\U6d4f\U89c8\U5230\U56fe\U7247\U63cf\U8ff0\n6\U3001\U4fee\U6539\U4e00\U4e9bbug";
    screenshotUrls =   
       
    sellerName = 
    supportedDevices =   
    trackCensoredName = 
    trackContentRating =
    trackId = 
    trackName = 
    trackViewUrl = "https://itunes.apple.com/us/app/quan-min-yu-jia-xue-xiao/id662004496?mt=8&uo=4";
    version = "1.0.1";
    wrapperType =


最后一步就是点击升级后的跳转界面

  1. - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex  
  2. {  
  3.     if (buttonIndex==1)  
  4.     {  
  5.         UIApplication *application = [UIApplication sharedApplication];  
  6.         [application openURL:[NSURL URLWithString:trackViewURL]];  
  7.     }  
  8. }  

欢迎您发表您的意见,建议,大家共同学习。

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多