1

I'm trying to create a WKNavigationDelegate for a WKWebView but have been unable to call the decisionHandler. Does anyone have any idea how to do this?

ObjC.registerSubclass({
    name: "test",
    methods: {
        "webView:decidePolicyForNavigationAction:decisionHandler:": {
             types: ["void", ["id", "id", "id"]],
             implementation: function(wv, navigationAction, decisionHandler) {
                 decisionHandler($.WKNavigationActionPolicyAllow);
                 return;
            }
        }
    }
});
var delegate = $['test'].alloc.init;
webView.navigationDelegate = delegate;

The code works up to the point where it prevents the navigation action but the decisionHandler is not called!

In the console I get the log:

Completion handler passed to -[test webView:decidePolicyForNavigationAction:decisionHandler:] was not called

Changing the type from "id" to "block" or "function" doesn't work.

mklement0
  • 382,024
  • 64
  • 607
  • 775
qwe
  • 11
  • 3

1 Answers1

1

I'd add a comment but confusing SO rules prohibit newbs from not answering (?!). Does adding protocols: ['WKNavigationDelegate'] to the registration help? Your method is being called, and $.WKNavigationActionPolicyAllow shows as being == 1, but maybe the protocol will assist type inference by JSC.

kfix
  • 628
  • 4
  • 12