检测版本更新

一 ,首先查看当前应用程序的最新版本
1.如果是AppStore上的应用 发送POST请求:http://itunes.apple.com/lookup?id=应用程序ID
如果是企业自己的服务器,就发送到该企业的服务器,以下代码是我正在做的项目
- ( void )checkVersion
{
    
//   发送网络请求
    
NSURL  *url = [ NSURL   URLWithString : @"http://218.206.179.179/ctp/ipauto/getLastedVersionInfo.do?code=000&type=release" ];
    
ASIHTTPRequest  *requst = [ ASIHTTPRequest   requestWithURL :url];
    [requst 
startAsynchronous ];
    requst.
delegate  =  self ;
}
2.解析服务器返回的数据得到最新版本并与当前版本比较
- ( void )requestFinished:( ASIHTTPRequest  *)request
{
    
NSDictionary  * dic = [ NSJSONSerialization   JSONObjectWithData :[request  responseData options : NSJSONReadingMutableContainers   error : NULL ];
    
NSArray  *detail = [dic  objectForKey : @"Detail" ];
    
NSString  *latestVersion = [[detail  firstObject objectForKey : @"version" ];
    
NSString  *appVersion = [ self   currentVersion ];
    
NSLog ( @"---%s----,-----%d------,%@" , __FUNCTION__ ,__LINE__,appVersion);
    
if  (![appVersion  isEqualToString :latestVersion]) {
        
UIAlertView  *alertView = [[ UIAlertView   alloc initWithTitle : @" 监测到有新版本 "  message: nil   delegate : self   cancelButtonTitle : @" 忽略 "  otherButtonTitles: @" 立即更新 " nil ];
        [alertView 
show ];
    }
    
}

二.如何获取当前版本
1.常用的,得到字符串
- ( NSString  *)currentVersion
{
    
//   获取当前版本字符串
    
NSDictionary  *infoDic = [[ NSBundle   mainBundle infoDictionary ];
    
NSString  *currentVer = [infoDic  objectForKey :( NSString  *) kCFBundleVersionKey ];
    
return  currentVer;
}
2.获取版本号,数字
     UInt32  versionNum =  CFBundleGetVersionNumber ( CFBundleGetMainBundle ());
不过,目前还不知道这个值用到哪里,发现AppStore返回的json没有相应的字段

三.打开新版本的下载页面
如果是在AppStore上的,可以点击按钮时,打开相应下载页面
企业自己发布的,可以使用Safari打开下载页面
这里关键是使用哪个URL
-( void )alertView:( UIAlertView  *)alertView didDismissWithButtonIndex:( NSInteger )buttonIndex
{
    
if  (buttonIndex ==  1 ) {
        
NSURL  *url = [ NSURL   URLWithString : @"http://218.207.242.142:8080/ots/beta.html" ];
        [[
UIApplication   sharedApplication openURL :url];
    }
}
打开AppStore如下
NSString  *str = [ NSString   stringWithFormat : @"itms-apps://ax.itunes.apple.com/WebObjects/MZStore.woa/wa/viewContentsUserReviews?type=Purple+Software&id=%@" , @"12345325" ];
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:str]];



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值