美文网首页
2019-05-30

2019-05-30

作者: Leon1024 | 来源:发表于2019-05-30 19:34 被阅读0次

    -(void)loadata{
    //获取appStore网络版本号
    AFHTTPSessionManager *manage = [AFHTTPSessionManager manager];
    //manage.requestSerializer = [AFJSONResponseSerializer serializer];
    manage.responseSerializer = [AFJSONResponseSerializer serializer];

    [manage    GET:@"http://api.fir.im/apps/latest/5cdc24d3959d697e4fce2bf3?api_token=d0fbb619001db343fb1b521134fa82d9" parameters:nil progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        NSDictionary *dic = responseObject;
        
        // NSDictionary *dics = self.updata;
        
        NSString *versions = [dic objectForKey:@"versionShort"];
        
        NSString *installUrl = [dic objectForKey:@"update_url"];
        NSString *name = [dic objectForKey:@"name"];
        NSLog(@"versions::::%@",versions);
        NSDictionary *infoDic=[[NSBundle mainBundle] infoDictionary];
        
        NSString *currentVersion=infoDic[@"CFBundleShortVersionString"];
        
        if (currentVersion == versions) {
            NSLog(@"BUNDLE_VERSION =========================%@",currentVersion);
            [self showAlertViewTitle:name subTitle:[NSString stringWithFormat:@"已检测到有新版本:%@",versions] openUrl:installUrl];
        }
       
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        NSLog(@"--------------errror:%@",error.localizedDescription);
    }];
    

    }

    -(void)showAlertViewTitle:(NSString *)title subTitle:(NSString *)subTitle openUrl:(NSString *)openUrl{
    UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:title message:subTitle preferredStyle:UIAlertControllerStyleAlert];
    UIAlertAction *cancel = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {

    }];
    UIAlertAction *sure = [UIAlertAction actionWithTitle:@"更新" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        
        if([[UIDevice currentDevice].systemVersion floatValue] >= 10.0){
            if ([[UIApplication sharedApplication] respondsToSelector:@selector(openURL:options:completionHandler:)]) {
                [[UIApplication sharedApplication] openURL:[NSURL URLWithString:openUrl] options:@{} completionHandler:^(BOOL success) {
                    
                }];
            } else {
                
                BOOL success = [[UIApplication sharedApplication] openURL:[NSURL URLWithString:openUrl]];
                NSLog(@"Open  %d",success);
            }
        } else{
            bool can = [[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:openUrl]];
            if(can){
                [[UIApplication sharedApplication] openURL:[NSURL URLWithString:openUrl]];
            }
        }
    }];
    [alertVC addAction:cancel];
    [alertVC addAction:sure];
    [self presentViewController:alertVC animated:YES completion:nil];
    

    }

    相关文章

      网友评论

          本文标题:2019-05-30

          本文链接:https://www.haomeiwen.com/subject/hgkbtctx.html