Class

SFSafariViewController

An object that provides a standard interface for browsing the web.

Overview

The view controller includes Safari features such as Reader, AutoFill, Fraudulent Website Detection, and content blocking. In iOS 9 and 10, it shares cookies and other website data with Safari. The user's activity and interaction with SFSafariViewController are not visible to your app, which cannot access AutoFill data, browsing history, or website data. You do not need to secure data between your app and Safari. If you would like to share data between your app and Safari in iOS 11 and later, so it is easier for a user to log in only one time, use SFAuthenticationSession instead.

UI features include the following:

  • A read-only address field with a security indicator and a Reader button

  • An Action button that invokes an activity view controller offering custom services from your app, and activities, such as messaging, from the system and other extensions

  • A Done button, back and forward navigation buttons, and a button to open the page directly in Safari

  • On devices that support 3D Touch, automatic Peek and Pop for links and detected data

To learn about 3D Touch, see 3D Touch in iOS Human Interface Guidelines and Adopting 3D Touch on iPhone.

Choosing the Best Web Viewing Class

If your app lets users view websites from anywhere on the Internet, use the SFSafariViewController class. If your app customizes, interacts with, or controls the display of web content, use the WKWebView class.

When you adopt SFSafariViewController and a user presses a link to peek at and then pop to the link’s destination, the user views web content from within your app. Tapping Done, the user returns to the view controller that was displayed before the web content was loaded. When you instead use the WKWebView class, Peek and Pop sends the user to Safari by default.

Topics

Creating a View Controller

init(url: URL, configuration: SFSafariViewController.Configuration)

Initializes and configures a Safari view controller that loads the specified URL.

class SFSafariViewController.Configuration

A configuration object that defines how a Safari view controller should be initialized.

init(url: URL)

Initializes a Safari view controller that loads the specified URL.

init(url: URL, entersReaderIfAvailable: Bool)

Initializes a Safari view controller that will load the specified URL, entering Reader mode if Reader mode is requested and available.

Deprecated

Responding to View Controller Interaction

var delegate: SFSafariViewControllerDelegate?

An object that provides behavior for the Safari view controller's Done and Action buttons.

protocol SFSafariViewControllerDelegate

A protocol used to implement custom event handling for a Safari view controller.

Configuring the View Controller

var configuration: SFSafariViewController.Configuration

A copy of the Safari view controller’s initialized configuration.

var preferredBarTintColor: UIColor?

The color to tint the background of the navigation bar and the toolbar.

var preferredControlTintColor: UIColor?

The color to tint the the control buttons on the navigation bar and the toolbar.

See Also

Display Safari Content in Your App

class SFAuthenticationSession

A class that manages sharing a one-time web service login, along with cookies and website data, between Safari and an app, which can also be used for automatic login for other associated apps.