swift2 WKWebview:处理来自应用程序的按钮单击事件

vmpqdwk3  于 2022-11-06  发布在  Swift
关注(0)|答案(1)|浏览(229)

我可以从我的应用程序中处理WKWebView的按钮单击事件吗?
简单地说,我在我的WKWebView中打开了一个Facebook登录页面。是否可以从我的应用程序中处理该登录按钮的事件?

byqmnocz

byqmnocz1#

您可以使用WKWebViewnavigationDelegate来侦听该操作。您应该实现的委托方法是:
雨燕

func webView(_ webView: WKWebView, decidePolicyFor navigationAction: WKNavigationAction, decisionHandler: @escaping (WKNavigationActionPolicy) -> Swift.Void)
{
    let request = navigationAction.request; // Inspect this request to see if it's from Facebook
    let policy = WKNavigationActionPolicyAllow or WKNavigationActionPolicyCancel depending if you want the request to continue firing or not
    decisionHandler( policy );
}

目标-C

- (void)webView:(WKWebView *)webView decidePolicyForNavigationAction:(WKNavigationAction *)navigationAction decisionHandler:(void (^)(WKNavigationActionPolicy))decisionHandler
{
    NSURLRequest *request = navigationAction.request; // Inspect this request to see if it's from Facebook
    WKNavigationActionPolicy policy = WKNavigationActionPolicyAllow or WKNavigationActionPolicyCancel depending if you want the request to continue firing or not
    decisionHandler( policy );
}

相关问题