webkit.messageHandlers
不是数组.这是一个UserMessageHandlersNamespace
.
尝试
var message = {"key1":"value1", "key2":"value2", "dictionary": {"name": "foo"}}
webkit.messageHandlers.foo.postMessage(message);
在您的消息处理程序中
public func userContentController(userContentController: WKUserContentController, didReceiveScriptMessage message: WKScriptMessage) {
let body = message.body
if let dict = body as? Dictionary {
print(dict)
}
}