iOS 提示是否更新

2016-12-06  本文已影响11人  Melody_YM
#pragma mark - 获取版本信息
-(void)getVerber{
    //创建请求(POST)
    NSString *urlString = @"http://itunes.apple.com/lookup";
    NSURL *url = [NSURL URLWithString:urlString];
    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
    //设置请求方法
    request.HTTPMethod = @"POST";
    NSMutableString *strM = [NSMutableString stringWithFormat:@"id=1151003567"];
    request.HTTPBody = [strM dataUsingEncoding:NSUTF8StringEncoding];
    //发送请求
    [[[NSURLSession sharedSession]dataTaskWithRequest:request completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
        if (data == nil) {
            return ;
        }else{
            NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingAllowFragments error:nil];
            NSArray *array = dic[@"results"];
            NSDictionary *dict = [array lastObject];
            if ([dict[@"version"] isEqualToString:@"1.0"]) {
                return ;
            }
            if ([dict[@"version"] length] == 0) {
                return ;
            }else{
                if ([dict[@"version"] isEqualToString:@"1.1"]) {
                    return ;
                }else{
//                    NSLog(@"123455");
                    [self addAlertViewController];
                }
            }
        }
        //执行完成之后的回调
//        NSLog(@"%s  %d   %@   %@",__func__,__LINE__,data,response);
    }] resume];
}
#pragma mark - 弹框提示是否更新
-(void)addAlertViewController{
    
    UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:@"提示" message:@"有新的版本,是否前往Apple Store更新?" preferredStyle:UIAlertControllerStyleAlert];
    
    UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil];
    UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"升级" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        
        NSString *str =@"itms-apps://itunes.apple.com/us/app/jue-ce/id1151003567?mt=8";
        
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:str]];
    }];
    [alertVC addAction:cancelAction];
    [alertVC addAction:okAction];
    
    [self presentViewController:alertVC animated:YES completion:nil];
}
上一篇下一篇

猜你喜欢

热点阅读