简体   繁体   English

是否可以在 SFSafariViewController 中自动接受弹出窗口?

[英]Is it possible to automatically accept Popups in SFSafariViewController?

I need to display a website in SFSafariViewController in an iPad app.我需要在 iPad 应用程序的SFSafariViewController中显示一个网站。 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.该网站(SAP Analytics Cloud 站点)不断要求用户显示用于身份验证的弹出窗口,尽管设备首选项中的切换开关已设置为允许弹出窗口,但每次触发弹出窗口时都会继续显示此警报。 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!我不打算发布任何 AppStore 版本,因此绝对欢迎任何 hacky 解决方案!

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.不幸的是,到目前为止,WebKit 还没有工作,我也知道对话是系统触发的,并且是 Apple 方面的隐私要求,但在我的用例中,它绝对不能显示。

弹出

I developed an app accessing an SAP Analytics Cloud site once and had the same problem.我曾经开发过一个访问 SAP Analytics Cloud 站点的应用程序,但遇到了同样的问题。 I couldn't solve it with SFSafariViewController at first, so I decided to go with WKWebView . SFSafariViewController我无法用SFSafariViewController解决它,所以我决定使用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.为此,您必须在 Info.plist 中提供NSCrossWebsiteTrackingUsageDescription并添加一个Settings.bundle文件。 (See Using NSCrossWebsiteTrackingUsageDescription to request user disable ITP for WKWebView ). (请参阅使用 NSCrossWebsiteTrackingUsageDescription 请求用户为 WKWebView 禁用 ITP )。 Doing so, the Authentication using Popups worked flawlessly.这样做,使用弹出窗口的身份验证完美无缺。
  • Implement the webView(webView: WKWebView, createWebViewWith configuration: WKWebViewConfiguration, for navigationAction: WKNavigationAction, windowFeatures: WKWindowFeatures) -> WKWebView?实现webView(webView: WKWebView, createWebViewWith configuration: WKWebViewConfiguration, for navigationAction: WKNavigationAction, windowFeatures: WKWindowFeatures) -> WKWebView? function from WKUIDelegate to create a small „Popup Webview“.来自WKUIDelegate函数来创建一个小的“Popup Webview”。 In your use case, you can set the frame to .zero to make it invisible.在您的用例中,您可以将框架设置为 .zero 以使其不可见。 Just make sure you return a WKWebView .只要确保你返回一个WKWebView
  • Implement webViewDidClose(_ webView: WKWebView) from WKUIDelegate to remove the popup from the superview once the Authentication completed.WKUIDelegate实现webViewDidClose(_ webView: WKWebView)以在身份验证完成后从WKUIDelegate中删除弹出窗口。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM