【问题标题】:WKWebView RunJavaScriptConfirmPanel Unable to locate the block to delegate conversion methodWKWebView RunJavaScriptConfirmPanel 找不到块来委托转换方法
【发布时间】:2018-04-12 13:32:35
【问题描述】:

我试图在 Xamarin.iOS 应用程序中捕获确认面板,但它仅适用于模拟器。

[Foundation.Export("webView:runJavaScriptConfirmPanelWithMessage:initiatedByFrame:completionHandler:")]
public void RunJavaScriptConfirmPanel(WKWebView webView, string message, WKFrameInfo frame, Action<bool> completionHandler)
{

    var alertController = UIAlertController.Create(null, message, UIAlertControllerStyle.ActionSheet);

    alertController.AddAction(UIAlertAction.Create("Sí", UIAlertActionStyle.Destructive, okAction =>
    {
        completionHandler(true);
    }));
    alertController.AddAction(UIAlertAction.Create("No", UIAlertActionStyle.Default, cancelAction =>
    {
        completionHandler(false);
    }));

    _controller.PresentViewController(alertController, true, null);

}

我正在关注 xamarin 官方页面 (https://developer.xamarin.com/recipes/ios/content_controls/web_view/handle_javascript_alerts/) 中的下一个示例,但是当我在 iPhone 8 plus 上运行该应用程序时出现此错误:

ObjCRuntime.RuntimeException: 无法为方法 XXXX.iOS.Infrastructure.JSDelegate.RunJavaScriptConfirmPanel 的参数 #4 找到要委托转换方法的块。请在http://bugzilla.xamarin.com 提交错误。

这是我正在使用的:

环境

iOS 11.3 Xcode 9.3 Xamarin.iOS:版本:11.9.1.24(Visual Studio 社区) Visual Studio Mac 7.4.2(内部版本 12)

有什么想法吗??我不明白为什么只能在模拟器中使用官方示例...

【问题讨论】:

    标签: javascript xamarin.ios ios11 wkwebview


    【解决方案1】:

    Xamarin 的示例仅在模拟器中工作,但我将方法签名更改为:

    public override void RunJavaScriptConfirmPanel(WKWebView webView, string message, WKFrameInfo frame, Action completionHandler) {

    没有任何 Foundation Export,现在正在模拟器和物理设备中工作。

    【讨论】:

      猜你喜欢
      • 2018-02-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-03
      • 2015-01-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多