2019-05-30

-(void)loadata{
//獲取appStore網(wǎng)絡(luò)版本號(hào)
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];

}

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

友情鏈接更多精彩內(nèi)容