ios 检测版本

废话不多说 直接上代码,喜欢的朋友帮忙点个赞

#pragma mark -- 检测版本 ---
//检测版本更新
-(void)onCheckVesion{
    NSDictionary *infoDic = [[NSBundle mainBundle] infoDictionary];
    //CFShow((__bridge CFTypeRef)(infoDic));
    NSString *currentVersion = [infoDic objectForKey:@"CFBundleVersion"];
    NSLog(@"当前版本的版本号----%@",currentVersion);
//如果是第一个版本,则直接返回
    if ([currentVersion isEqualToString:@"1"]) {
        DXAlertView *alert = [[DXAlertView alloc]initWithTitle:@"温馨提示" contentText:@"已是最新版本" leftButtonTitle:@"知道了" rightButtonTitle:@"取消"];
        [alert show];
        return;
    }
    NSString *URL = @"http://itunes.apple.com/lookup?id=1035222784";//在商店里面的appid
    [LORequestManger POST:URL params:nil success:^(id response) {
        NSDictionary *dic = response;
        NSArray *infoArray = [dic objectForKey:@"results"];
        if ([infoArray count]) {
            NSDictionary *releaseInfo = [infoArray objectAtIndex:0];
            NSString *lastVersion = [releaseInfo objectForKey:@"version"];
            NSLog(@"appstore上面的版本号是-----%@",lastVersion);
            NSString *trackViewURL = [releaseInfo objectForKey:@"trackVireUrl"];
            NSLog(@"----trackviewURL === %@",trackViewURL);
            if (![lastVersion isEqualToString:currentVersion]) {
                //trackViewURL = [releaseInfo objectForKey:@"trackVireUrl"];
                UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"任务管理" message:@"有新的版本更新,是否前往更新?" delegate:self cancelButtonTitle:@"关闭" otherButtonTitles:@"更新", nil];
                alert.tag = 10000;
                [alert show];
            }
            else
            {
                UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"任务管理" message:@"此版本为最新版本" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
                alert.tag = 10001;
                [alert show];
            }
        }
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        
        NSLog(@"%@",error);
    }];
}
//更新按钮的点击事件
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    if (alertView.tag==10000) {
        if (buttonIndex==1) {
            NSURL *url = [NSURL URLWithString:@"https://itunes.apple.com"];
            [[UIApplication sharedApplication]openURL:url];
        }
    }
}

你可能感兴趣的:(ios 检测版本)