Search code examples
iosswiftsafaripopupsfsafariviewcontroller

Is it possible to automatically accept Popups in SFSafariViewController?


I need to display a website in SFSafariViewController in an iPad app. The website (an SAP Analytics Cloud Site) continuously asks the user for showing a Popup for authentication and although the toggles in the device's preferences are already set to allow pop-ups, this alert keeps showing up every time a popup is triggered. The "Allow" decision is not even persisted for the current session.

--> Is there a possibility to allow it automatically so that the user does not see this alert?

I'm not planning an AppStore release whatsoever so any hacky solutions are definitely welcome!

Unfortunately, WebKit did not work so far and I also know the dialogue is system-triggered and an Apple-side privacy requirement, but in my use case it must not be shown by all means.

Pop-Up


Solution

  • I developed an app accessing an SAP Analytics Cloud site once and had the same problem. I couldn't solve it with SFSafariViewController at first, so I decided to go with WKWebView. Eventually, it worked for me this way:

    • Enable Cross Site Tracking for the App. To do so you have to provide a NSCrossWebsiteTrackingUsageDescription in the Info.plist and also add a Settings.bundle file. (See Using NSCrossWebsiteTrackingUsageDescription to request user disable ITP for WKWebView). Doing so, the Authentication using Popups worked flawlessly.
    • Implement the webView(webView: WKWebView, createWebViewWith configuration: WKWebViewConfiguration, for navigationAction: WKNavigationAction, windowFeatures: WKWindowFeatures) -> WKWebView? function from WKUIDelegate to create a small „Popup Webview“. In your use case, you can set the frame to .zero to make it invisible. Just make sure you return a WKWebView.
    • Implement webViewDidClose(_ webView: WKWebView) from WKUIDelegate to remove the popup from the superview once the Authentication completed.