美文网首页
自动更新弹出框

自动更新弹出框

作者: ios_暗夜行者 | 来源:发表于2021-04-09 11:26 被阅读0次

pragma mark++++++ 可选-自动更新弹出框 +++++++++

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

}];
UIAlertAction *sure = [UIAlertAction actionWithTitle:LocalizedString(@"更新") 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];

}

pragma mark++++++ 强制-自动更新弹出框 +++++++++

-(void)showAlertViewTitle2:(NSString *)title subTitle:(NSString *)subTitle openUrl:(NSString *)openUrl{
UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:title message:subTitle preferredStyle:UIAlertControllerStyleAlert];

UIAlertAction *sure = [UIAlertAction actionWithTitle:LocalizedString(@"更新") 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:sure];
[self presentViewController:alertVC animated:YES completion:nil];

}

推荐一个iOS拉取App Store里面的app自动更新的第三方库
Git地址:https://github.com/wolfhous/HSUpdateApp

相关文章

网友评论

      本文标题:自动更新弹出框

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