Search code examples
ioscookieswebviewmobile-safarisfsafariviewcontroller

SfSafariViewController and shared cookie storage


SFSafariViewController(SVC) was introduced in iOS 9 and SVC can read cookies from Mobile safari and not from the app and it can write cookies and it can be accessed by Mobile Safari and not mobile app.

The above behaviour was same till iOS 10.

Starting from iOS 11 SVC can't read cookies of Mobile Safari.

So where are the things standing at cookie sharing as of iOS 11 ?

Where SVC stores it's cookies from iOS 11 ?

Does SVC store the cookie inside the launching app itself ?

If yes , can webview(UIWebview/Wkwebview) in app read the cookies written by SVC

If yes, can SVC read the cookies written by Webview

If no , can SVC read the cookies that it wrote during the last session

or SVC is more like incongnito version of Safari where it doesn't remember previous session and it can't access the cookies of both webview of the app and Mobile Safari.


Solution

  • Where SVC stores it's cookies from iOS 11 ?

    The cookies/other data is currently saved under your container in SystemData/com.apple.SafariViewService/Library and then under Cookies and Webkit/WebsiteData - This may change in future versions!

    Does SVC store the cookie inside the launching app itself ?

    Yes, in your container

    If yes , can webview(UIWebview/Wkwebview) in app read the cookies written by SVC

    Not out of the box, you could load the web views using a custom URLRequest and then have it read these files, I would not recommend it as the format currently saved is undocumented and may change in the future.

    If no , can SVC read the cookies that it wrote during the last session

    Yes, SFSafariViewController maintains it's data from previous sessions, it is private for your application as it is stored in your container.