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"]];
    }
}

你可能感兴趣的:(iOS 应用版本检测更新)