SFSafariViewController

To display web content in iOS applications we have following options,

  • openURL to open content in Safari app
  • UIWebView
  • WKWebView
  • SFSafariViewController

The first option simply navigates the user to the safari app and opens the URL provided. Once we do this we have no control over the viewed content as this is Safari not our app. The worst thing about this, is that the user switches the app. In a world where every app wants go grab user eyes we have lost one.

The UIWebView and WKWebView provides solution to the app switiching problem by providing web experience inside our app. Though these provide lots of handling point and customisations(WKWebView to be more specific), these are UIViews and to make them look like safari with all of its features, its a hard task for developer.

So if one needs, Safari like web experience and Avoid app switching, SFSafariViewController is to their help.

SFSafariViewController is a view controller for displaying web content in a Safari-like interface with some of Safari’s features. The web content in SFSafariViewController shares cookie and website data with web content opened in Safari.

It also shares the reading mode settings that user has configured in the safari app.

Few features of SFSafariViewController are,

  • Reading mode
  • Next previous pages button
  • Action button
  • Top bar with visible url (only visible if the SFSafariViewController instance does navigation bar, i.e. when it is modally presented. When it is pushed on the navigation stack, the navigation contollers navigation bar replaces SFSafariViewController’s top bar)

Here is how to use it,