使用 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];