Home Mobile iOS Programming Should I use WKWebView or SFSafariViewController for web views in my app?...

Should I use WKWebView or SFSafariViewController for web views in my app? from News – Apple Developer

3 min read

Whether your app needs to provide a full web browsing experience, display richly-styled content, or incorporate external websites without taking people out of your app, you can make the experience smooth and seamless by choosing the right API.

You can display web content inside of your app with both the WKWebView and SFSafariViewController APIs. But which is the best for your app’s needs?

Learn Programming & Development with a Packt Subscription

WKWebView is part of the WebKit framework: It allows you to embed web content into your app as a seamless part of your app’s UI. You can present a full or partial view of web content directly in your app by loading a view that leverages existing HTML, CSS, and JavaScript content or create your own if your layout and styling requirements are better satisfied by using web technologies.

Note: If your app uses the deprecated UIWebView API to display web content, you should update your code for improved security, performance, and reliability. Learn more:

Deadline extended for app updates using UIWebView

SFSafariViewController is part of the SafariServices framework, and lets your users browse a web page, or a website right inside your app. With it, people can enjoy the same web browsing experience they get in Safari — including features like Password Autofill, Reader, and Secure Browsing — without ever having to leave your app.

These two APIs can provide a lot of the heavy lifting for web technologies in your app, though there are a few instances where we recommend alternative frameworks. For example, when presenting a web-based login screen for your app, use ASWebAuthenticationSession to provide people with the most secure experience.

When should I use WKWebView?

If you need to customize or control the display of web content — or interact with the content itself — WKWebView will be most flexible in helping you build the implementation that suits your needs. (If your app is designed to be used offline, make sure any WKWebView content has appropriate fallbacks and alerts.)

Additionally, consider WKWebView if you need to display HTML or CSS content inline or as part of rest of your app’s user interface.

The Washington Post’s development team implemented WKWebView to display content from the Washington Post website within their app.

In short, WKWebView is an incredibly powerful technology that works in tandem with iOS and macOS frameworks. That said, WKWebView is not designed to outright replace system technologies and frameworks. For example, you should avoid using it in place of device-optimized UIKit classes like UITableView, UIImage, and UIButton, as you lose out on core system behaviors and provide a subpar experience for people who use your app.

When should I use SFSafariViewController?

When you want display websites inside your app without sending people to Safari, the best tool is SFSafariViewController. By using this API, you can effectively embed the Safari interface — and many of its key features and privacy protections — into your app.

The Apple Developer app displays web links through SFSafariViewController.

SFSafariViewController is best used when you need to display interactive web experiences on websites you don’t own, or showcase parts of your web content that are generally outside the scope of your app.




  • WWDC17

What’s New in Safari View Controller

Safari View Controller brings Safari’s features into your app for browsing the web and logging in with 3rd party services. Learn how to use new APIs to customize Safari View Controller’s UI to fit your app’s style.

  • WWDC17

Customized Loading in WKWebView

WKWebView allows you to seamlessly integrate web content into your app. Learn how new features in WKWebView allow you to manage cookies, filter unwanted content, and give you more control over loading web content.