iOS 提示是否更新

#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];
}
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

友情链接更多精彩内容