iOS 应用版本检测更新

-( void )checkVersion:( id )sender{
   
   
dict_version =[[sender objectFromJSONData ] copy ];
   
   
// 获取用户安装当前客户端的版本号
   
NSDictionary *infoDictionary = [[ NSBundle mainBundle ] infoDictionary ];
   
// 版本号存入数组
   
NSString *now_version = [infoDictionary objectForKey : @"CFBundleVersion" ];
   
// 版本号存入数组
   
NSArray *local_version_arr=[now_version componentsSeparatedByString : @"." ];
   
NSLog(@"local_version_arr is %@",local_version_arr);
   
   
// 从服务器获取的版本号
   
NSString *new_version = [ dict_version objectForKey : @"version" ];
   
// 从服务器获取的更新内容
   
NSString *updateContern = [ dict_version objectForKey : @"update_content" ];
   
   
// 判断获取的内容是不是正确
   
if (![new_version isEqual :[ NSNull null ]] && ![new_version isEqual : @"" ]) {
       
// 将版本号以 “.” 为间隔存入数组中
       
NSArray *new_version_arr=[new_version componentsSeparatedByString : @"." ];
       
// 比较服务器版本号和当前应用版本号
       
for ( int i= 0 ; i<[new_version_arr count ];i++ ) {
           
if ([[new_version_arr objectAtIndex :i] intValue ]>[[local_version_arr objectAtIndex :i] intValue ]) {
               
UIAlertView *updateAlert=[[ UIAlertView alloc ] initWithTitle : @" 版本更新提示 " message :updateContern delegate : self cancelButtonTitle : @" 稍后提示 " otherButtonTitles : @" 现在更新 " , nil ];
                [updateAlert
show ];
                [updateAlert
release ];
               
break ;
            }
else if ([[new_version_arr objectAtIndex :i] intValue ]==[[local_version_arr objectAtIndex :i] intValue ]) {
               
continue ;
            }
else {
               
return ;
            }
        }
    }
}
#pragma mark - uialert delegate
- ( void )alertView:( UIAlertView *)alertView clickedButtonAtIndex:( NSInteger )buttonIndex{
   
   
if (buttonIndex == 1 ) {
       
NSLog ( @"downloadUrl is %@" ,[ dict_version objectForKey : @"downloadUrl" ]);
       [[UIApplication sharedApplication ] openURL :[ NSURL URLWithString :[ dict_version objectForKey : @"downloadUrl"]]];

                // [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"itms-services://?action=download-manifest&url=https://xxx.plist"]];
    }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值