Interface WKScriptMessageHandlerWithReply


  • public interface WKScriptMessageHandlerWithReply
    A class conforming to the WKScriptMessageHandlerWithReply protocol provides a method for receiving messages from JavaScript running in a webpage and replying to them asynchronously.
    • Method Detail

      • userContentControllerDidReceiveScriptMessageReplyHandler

        void userContentControllerDidReceiveScriptMessageReplyHandler​(WKUserContentController userContentController,
                                                                      WKScriptMessage message,
                                                                      WKScriptMessageHandlerWithReply.Block_userContentControllerDidReceiveScriptMessageReplyHandler replyHandler)
        Invoked when a script message is received from a webpage. When the JavaScript running in your application's web content called window.webkit.messageHandlers..postMessage(), a JavaScript Promise object was returned. The values passed to the replyHandler are used to resolve that Promise. Passing a non-nil NSString value to the second parameter of the replyHandler signals an error. No matter what value you pass to the first parameter of the replyHandler, the Promise will be rejected with a JavaScript error object whose message property is set to that errorMessage string. If the second parameter to the replyHandler is nil, the first argument will be serialized into its JavaScript equivalent and the Promise will be fulfilled with the resulting value. If the first argument is nil then the Promise will be resolved with a JavaScript value of "undefined" Allowed non-nil result types are: NSNumber, NSNull, NSString, NSDate, NSArray, and NSDictionary. Any NSArray or NSDictionary containers can only contain objects of those types. The replyHandler can be called at most once. If the replyHandler is deallocated before it is called, the Promise will be rejected with a JavaScript Error object with an appropriate message indicating the handler was never called. Example: With a WKScriptMessageHandlerWithReply object installed with the name "testHandler", consider the following JavaScript:
        Parameters:
        userContentController - The user content controller invoking the delegate method.
        message - The script message received.
        replyHandler - A block to be called with the result of processing the message.