[英]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:最终,它以这种方式对我有用:
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.这样做,使用弹出窗口的身份验证完美无缺。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
。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.