Search code examples
iosswiftuiwebviewsfsafariviewcontroller

Is it possible to save SFSafariViewController state instead of reloading webpage?


I'm trying to open a YouTube playlist from a tabBar, allow the user to play a video, but I want the user to be able to pause the video, go back to the app and resume to the video when they re-open that tab.

Is this possible in SFSafariView or UIWebView?


Solution

  • First, UIWebView has been deprecated so you should look into WKWebView.

    The main difference between SFSafariViewController and WKWebView is how much control you want to keep on the web experience.

    From Apple Guideline Should I use WKWebView or SFSafariViewController for web views in my app?, you can use SFSafariViewController when you want Safari web experience embedded within your app. Although you'll have a very limited control of it: caching or user session isn't part of it. That being said, if the web page handles an authentication system with user session, you could potentially recover it using ASWebAuthenticationSession.

    On the other side, WKWebView allows you much more customisation and hands on for the web session and navigation. This is probably what you're looking for if you want to keep control of user's navigation.