Contents

userContentController(_:didReceive:replyHandler:)

Tells the handler that a webpage sent a script message that included a reply.

Declaration

func userContentController(_ userContentController: WKUserContentController, didReceive message: WKScriptMessage, replyHandler: @escaping @MainActor @Sendable (Any?, String?) -> Void)
func userContentController(_ userContentController: WKUserContentController, didReceive message: WKScriptMessage) async -> (Any?, String?)

Parameters

  • userContentController:

    The user content controller that delivered the message to your handler.

  • message:

    An object that contains the message details.

  • replyHandler:

    A reply handler block to execute with the response to send back to the webpage. This block has no return value and takes the following parameters:

    reply

    An object that contains the data to return to the webpage. Allowed types for this parameter are Nsnumber, Nsstring, Nsdate, Nsarray, Nsdictionary, and Nsnull. Specify nil if an error occurred.

    errorMessage

    nil on success, or a string that describes the error that occurred.

Discussion

Use this method to handle a message from the webpage and provide an appropriate response.

See Also

Receiving Messages