Should I use WKWebView or SFSafariViewController for web views in my app?

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?

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

View now

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.


Resources

WKWebView

SFSafariViewController