Open a URL with SafariViewController

suggest change

Don’t forget to import the necessary framework first.

import SafariServices
@import SafariServices;

Instantiate a SafariViewController instance. This is Swift 3. URL(string:) returns nil for a string that is not a URL.

let safariVC = SFSafariViewController(url: URL(string: "https://www.google.com")!)
NSURL *URL = [NSURL URLWithString:@"http://www.google.com"];
SFSafariViewController *sfvc = [[SFSafariViewController alloc] initWithURL:URL];

Optionally you can also tell SafariViewController to enter reading mode if possible once it’s done loading. entersReaderIfAvailable was deprecated in iOS 11; create the controller with an SFSafariViewController.Configuration instead.

let safariVC = SFSafariViewController(url: URL(string: "https://www.google.com")!, entersReaderIfAvailable: true)
NSURL *URL = [NSURL URLWithString:@"http://www.google.com"];
SFSafariViewController *sfvc = [[SFSafariViewController alloc] initWithURL:URL entersReaderIfAvailable:YES];

Present the view controller.

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

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents