Mik*_*ynn 18
这适用于像10这样的新版本.
NSURL *URL = [NSURL URLWithString:[NSString stringWithFormat:@"http://google.com"]];
if ([SFSafariViewController class] != nil) {
SFSafariViewController *sfvc = [[SFSafariViewController alloc] initWithURL:URL];
[self presentViewController:sfvc animated:YES completion:nil];
} else {
[[UIApplication sharedApplication] openURL:URL];
}
Run Code Online (Sandbox Code Playgroud)
小智 8
这是一个版本,用于检查iOS版本以处理iOS 8,如果SFSafariViewController不兼容,则在Safari中打开链接
NSURL *URL = [NSURL URLWithString:[NSString stringWithFormat:@"http://google.com"]];
if ([[UIDevice currentDevice].systemVersion hasPrefix:@"9"]) {
SFSafariViewController *sfvc = [[SFSafariViewController alloc] initWithURL:URL];
[self presentViewController:sfvc animated:YES completion:nil];
} else {
[[UIApplication sharedApplication] openURL:URL];
}
Run Code Online (Sandbox Code Playgroud)
然后还调用它来处理完成按钮
- (void)safariViewControllerDidFinish:(nonnull SFSafariViewController *)controller {
[controller dismissViewControllerAnimated:YES completion:nil];}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5317 次 |
| 最近记录: |