您的位置:首页 > 移动开发 > IOS开发

ios 版本更新功能

2016-03-04 16:12 651 查看
-(void)getAppVersion{
    //或者本地app版本号  version
    NSString* versionnum = [[[NSBundle
mainBundle] infoDictionary]
objectForKey:@"CFBundleShortVersionString"];
    //bulid
    NSString* versionbuild = [[[NSBundle
mainBundle] infoDictionary]
objectForKey:@"CFBundleVersion"];
    NSLog(@"versionbuild:%@",versionbuild);
        NSMutableDictionary * dic = [NSMutableDictionary
dictionaryWithCapacity:1];
    [dic setObject:@"2"
forKey:@"type"];
    [[NetworkSingleton
sharedManager]GetAppVersion:dic
successBlock:^(id responseBody){
        NSLog(@"========获取版本信息result======:%@",responseBody);
        NSDictionary* dicJson = responseBody;
        NSString* zhuNum = [dicJson
valueForKey:@"major"];
        zhuNum = [NSString
stringWithFormat:@"%@",zhuNum];
        NSString* ziNum = [dicJson
valueForKey:@"minor"];
        ziNum = [NSString
stringWithFormat:@"%@",ziNum];
        NSString* gengxinNum = [dicJson
valueForKey:@"revision"];
        gengxinNum = [NSString
stringWithFormat:@"%@",gengxinNum];
        NSString* versionFromSever = [NSString
stringWithFormat:@"%@.%@",zhuNum,ziNum];
        if ([versionFromSever
isEqualToString:versionnum] && [gengxinNum
isEqualToString:versionbuild]) {
            NSLog(@"已经是最新版本,无需更新");
        }else{           
            NSLog(@"有新版本,点击更新");
            UIAlertView* tips = [[UIAlertView
alloc]initWithTitle:@"提示"
message:@"您有新版本可以更新,点击确定可以下载!"
delegate:self
cancelButtonTitle:@"取消"
otherButtonTitles:@"确定",
nil];
            [tips show];
        }
    } failureBlock:^(NSString *error){
        NSLog(@"请求失败:%@",error);
    }];

}
==============================

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
    if (alertView.tag ==
98705) {
        if (buttonIndex ==
1) {
            if (type) {
                [self
skipWithTypePush:type];
            }
        }
        return;
    }
    if (buttonIndex ==
0) {
        
        NSLog(@"取消");
    }else
if (buttonIndex == 1){
        NSLog(@"跳转");
        NSString *iTunesLink =
@"itms-apps://itunes.apple.com/us/app/APP的名字的中文拼音用-分割开。如微信(wei-xin)/id你app的商户ID?mt=8";
        [[UIApplication
sharedApplication] openURL:[NSURL
URLWithString:iTunesLink]];
    }
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  ios开发 ios