{"id":116036,"date":"2020-07-29T16:00:20","date_gmt":"2020-07-29T16:00:20","guid":{"rendered":"https:\/\/developer.apple.com\/news\/?id=trjs0tcd"},"modified":"2020-07-29T16:00:20","modified_gmt":"2020-07-29T16:00:20","slug":"should-i-use-wkwebview-or-sfsafariviewcontroller-for-web-views-in-my-app","status":"publish","type":"post","link":"https:\/\/sickgaming.net\/blog\/2020\/07\/29\/should-i-use-wkwebview-or-sfsafariviewcontroller-for-web-views-in-my-app\/","title":{"rendered":"Should I use WKWebView or SFSafariViewController for web views in my app?"},"content":{"rendered":"<div class=\"inline-article-image\"><img decoding=\"async\" src=\"https:\/\/www.sickgaming.net\/blog\/wp-content\/uploads\/2020\/07\/should-i-use-wkwebview-or-sfsafariviewcontroller-for-web-views-in-my-app.jpg\" data-hires=\"false\"><\/div>\n<p>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.<\/p>\n<p>You can display web content inside of your app with both the WKWebView and SFSafariViewController APIs. But which is the best for your app\u2019s needs?<\/p>\n<p><strong>WKWebView<\/strong> is part of the WebKit framework: It allows you to embed web content into your app as a seamless part of your app\u2019s 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.<\/p>\n<hr>\n<p><em>Note: If your app uses the deprecated UIWebView API to display web content, you will need to update your code as soon as possible for improved security, performance, and reliability. Learn more:<\/em><\/p>\n<p><a href=\"https:\/\/developer.apple.com\/news\/?id=12232019b\" class=\"icon icon-after icon-chevronright\">Updating Apps that Use Web Views<\/a><\/p>\n<hr>\n<p><strong>SFSafariViewController<\/strong> 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 \u2014 including features like Password Autofill, Reader, and Secure Browsing \u2014&nbsp;without ever having to leave your app.<\/p>\n<p>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.<\/p>\n<h3>When should I use WKWebView?<\/h3>\n<p>If you need to customize or control the display of web content \u2014&nbsp;or interact with the content itself \u2014 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.)<\/p>\n<p>Additionally, consider WKWebView if you need to display HTML or CSS content inline or as part of rest of your app\u2019s user interface.<\/p>\n<div class=\"inline-article-image\"><img decoding=\"async\" src=\"https:\/\/www.sickgaming.net\/blog\/wp-content\/uploads\/2020\/07\/should-i-use-wkwebview-or-sfsafariviewcontroller-for-web-views-in-my-app-1.jpg\" data-hires=\"false\"><\/p>\n<p class=\"typography-caption\">The Washington Post\u2019s development team implemented WKWebView to display content from the Washington Post website within their app.<\/p>\n<\/div>\n<p>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.<\/p>\n<h3>When should I use SFSafariViewController?<\/h3>\n<p>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 \u2014&nbsp;and many of its key features and privacy protections \u2014&nbsp;into your app. <\/p>\n<div class=\"inline-article-image\"><img decoding=\"async\" src=\"https:\/\/www.sickgaming.net\/blog\/wp-content\/uploads\/2020\/07\/should-i-use-wkwebview-or-sfsafariviewcontroller-for-web-views-in-my-app-2.jpg\" data-hires=\"false\"><\/p>\n<p class=\"typography-caption\">The Apple Developer app displays web links through SFSafariViewController.<\/p>\n<\/div>\n<p>SFSafariViewController is best used when you need to display interactive web experiences on websites you don\u2019t own, or showcase parts of your web content that are generally outside the scope of your app.<\/p>\n<hr>\n<h3>Resources<\/h3>\n<p><a href=\"https:\/\/developer.apple.com\/documentation\/webkit\/wkwebview\" class=\"icon icon-after icon-chevronright\">WKWebView<\/a><\/p>\n<p><a href=\"https:\/\/developer.apple.com\/documentation\/safariservices\/sfsafariviewcontroller\" class=\"icon icon-after icon-chevronright\">SFSafariViewController<\/a><\/p>\n<section class=\"grid activity\">\n<section class=\"row\">\n<section class=\"column large-4 small-4 no-padding-top no-padding-bottom\"><a href=\"https:\/\/developer.apple.com\/wwdc17\/220\" class=\"activity-image-link\"> <img decoding=\"async\" class=\"actiity-image medium-scale\" width=\"250\" src=\"https:\/\/www.sickgaming.net\/blog\/wp-content\/uploads\/2020\/07\/should-i-use-wkwebview-or-sfsafariviewcontroller-for-web-views-in-my-app-3.jpg\" data-hires=\"false\" alt><\/a> <\/section>\n<section class=\"column large-8 small-8 padding-left-small padding-top-small padding-bottom-small no-padding-top no-padding-bottom\"><a href=\"https:\/\/developer.apple.com\/wwdc17\/220\"> <\/p>\n<h4 class=\"no-margin-bottom activity-title\">Customized Loading in WKWebView<\/h4>\n<p> <\/a> <\/p>\n<p class=\"activity-description\">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.<\/p>\n<\/section>\n<\/section>\n<\/section>\n<section class=\"grid activity\">\n<section class=\"row\">\n<section class=\"column large-4 small-4 no-padding-top no-padding-bottom\"><a href=\"https:\/\/developer.apple.com\/wwdc17\/225\" class=\"activity-image-link\"> <img decoding=\"async\" class=\"actiity-image medium-scale\" width=\"250\" src=\"https:\/\/www.sickgaming.net\/blog\/wp-content\/uploads\/2020\/07\/should-i-use-wkwebview-or-sfsafariviewcontroller-for-web-views-in-my-app-4.jpg\" data-hires=\"false\" alt><\/a> <\/section>\n<section class=\"column large-8 small-8 padding-left-small padding-top-small padding-bottom-small no-padding-top no-padding-bottom\"><a href=\"https:\/\/developer.apple.com\/wwdc17\/225\"> <\/p>\n<h4 class=\"no-margin-bottom activity-title\">What&#8217;s New in Safari View Controller<\/h4>\n<p> <\/a> <\/p>\n<p class=\"activity-description\">Safari View Controller brings Safari\u2019s 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\u2019s UI to fit your app\u2019s style.<\/p>\n<\/section>\n<\/section>\n<\/section>\n","protected":false},"excerpt":{"rendered":"<p>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 [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":116037,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[55],"tags":[],"class_list":["post-116036","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-apple-developer-news"],"_links":{"self":[{"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/posts\/116036","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/comments?post=116036"}],"version-history":[{"count":0,"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/posts\/116036\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/media\/116037"}],"wp:attachment":[{"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/media?parent=116036"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/categories?post=116036"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/tags?post=116036"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}