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
网友评论