使用 SafariViewController 打开 URL

不要忘记先导入必要的框架。

import SafariServices
//Objective-C
@import SafariServices;

实例化 SafariViewController 实例。

let safariVC = SFSafariViewController(URL: URL(string: "your_url")!)
//Objective-C
@import SafariServices;
NSURL *URL = [NSURL URLWithString:[NSString stringWithFormat:@"http://www.google.com"]];
SFSafariViewController *sfvc = [[SFSafariViewController alloc] initWithURL:URL];

(可选)一旦加载完成,你也可以告诉 SafariViewController 进入阅读模式。

let safariVC = SFSafariViewController(URL: URL(string: "your_url")!, entersReaderIfAvailable: true)
//Objective-C
NSURL *URL = [NSURL URLWithString:[NSString stringWithFormat:@"http://www.google.com"]];
SFSafariViewController *sfvc = [[SFSafariViewController alloc] initWithURL:URL entersReaderIfAvailable:YES];

呈现视图控制器。

present(safariVC, animated: true, completion: nil)
//Objective-C
[self presentViewController:sfvc animated:YES completion:nil];