Search code examples
iosnativesfsafariviewcontroller

SFSafariViewController - Interacting with the parent app from a web-page


I'm trying to research a way to load a web view controller into an iOS app, such that the web page can communicate data back up to the parent.

Is this possible with SFSafariViewController? Is there some mechanism like post-messaging, which will let me send data back up to the native app?

Note: it's pretty important that I use SFSafariViewController, since I also need the web view to persist/share cookies with Safari.


Solution

  • Since SFSafariViewControllers are not sandboxed, like all other implementations of UIWebView, it means that they have access to private information, such as cookies.

    As a safety measure, the SFSafariViewController is then sandboxed from the rest of the app. The one way to communicate between it and your app is through a custom URL scheme.

    The drawback of this is that you need to be in control of the web-service, and implement an API for this purpose (however you shouldn't really be able to access cookies otherwise).

    You can follow this project to get you started.

    Hope this helps,

    Liam