I know that SFSafariViewController
has private cookie storage and other implementations. However, I know that we may write an extension for every (every native system) Swift class.
I need either to share cookies with native Safari, or to open Safari
from my app with some header request. At least, how to create an API
for getting/setting cookies?

- 52,648
- 24
- 135
- 213

- 109
- 2
- 13
1 Answers
- Cookie sharing between SFSafariVC and native Safari has been disabled in iOS >= 11.
At WWDC, Apple announced a change in the behavior of Safari View Controller with iOS 11 in that stored data (cookies, local storage, etc.) will no longer be shared between instances of Safari View Controller. We've confirmed this in-house with a beta version, and this seems to be independently confirmed by the folks at Branch.
From AppAuth-iOS' repo: user whitehatguy
- The only API for SFSafariVC is to create a new instance for a given URL. You can't set or modify cookies.
If you need to execute custom code, have a look at WKWebView (iOS >= 8) / UIWebView (iOS < 8). Useful answers: Getting cookies in WKWebView
SFAuthenticationSession was created to allow SSO/OAuth authentication flows, which shares cookies with native Safari but developers have no direct access.
A class that manages sharing a one-time web service login, along with cookies and website data, between Safari and an app, which can also be used for automatic login for other associated apps.
The two cases where you would use SFAuthenticationSession are:
- Logging in to a third party's service using an authentication protocol (e.g. OAuth). This option works well for social network applications.
- Providing a single sign-on (SSO) experience for applications. This option works well for enterprise companies that have many applications installed on the same device.
SFAuthenticationSession's documentation by Apple
-
Ok, thanks, but I still don't understand answer #2: why can't we write an extension to work with some private methods/properties? – slesher Aug 12 '17 at 20:55
-
You can't access private API. Even if you could, your app would never pass App Store approval. Even so, as stated above, SFSafariVC doesn't even share cookies with native Safari (*anymore*). – nathan Aug 12 '17 at 20:56
-
Ok, so do you have any suggestions/workarounds how to reach this? May I write an extension for that? This is connected: https://stackoverflow.com/questions/45652212/find-out-the-urlrequest-of-wkwebview – slesher Aug 12 '17 at 22:09
-
The question was related to SFSafariVC. If you are looking to manipulate cookies using WKWebView, please create a new question. – nathan Aug 12 '17 at 22:10