harmony 鸿蒙ArkWeb_WebMessagePortAPI

  • 2025-06-12
  • 浏览 (5)

ArkWeb_WebMessagePortAPI

Overview

Defines a native API struct of the post message. Before calling the API, you are advised to use ARKWEB_MEMBER_MISSING to check whether the function struct has the corresponding pointer to avoid crash caused by mismatch between the SDK and the device ROM.

Since: 12

Related module: Web

Summary

Member Variables

Name Description
size_t size Size of the struct.
ArkWeb_ErrorCode(* postMessage )(const ArkWeb_WebMessagePortPtr webMessagePort, const char *webTag, const ArkWeb_WebMessagePtr webMessage) Pointer to the function used to send the message to the HTML page.
void(* close )(const ArkWeb_WebMessagePortPtr webMessagePort, const char *webTag) Pointer to the function used to close the message port.
void(* setMessageEventHandler )(const ArkWeb_WebMessagePortPtr webMessagePort, const char *webTag, ArkWeb_OnMessageEventHandler messageEventHandler, void *userData) Pointer to the callback used to set the HTML messages received.

Member Variable Description

close

void(* ArkWeb_WebMessagePortAPI::close) (const ArkWeb_WebMessagePortPtr webMessagePort, const char *webTag)

Description

Pointer to the function used to close the message port.

Parameters

Name Description
webMessagePort Pointer to the message port.
webTag Name of a Web component.

postMessage

ArkWeb_ErrorCode(* ArkWeb_WebMessagePortAPI::postMessage) (const ArkWeb_WebMessagePortPtr webMessagePort, const char *webTag, const ArkWeb_WebMessagePtr webMessage)

Description

Pointer to the function used to send the message to the HTML page.

Parameters

Name Description
webMessagePort Pointer to the message port.
webTag Name of a Web component.
webMessage Message to send.

Returns

Returns ARKWEB_SUCCESS if the operation is successful. Returns ARKWEB_INVALID_PARAM if the parameter is invalid. Returns ARKWEB_INIT_ERROR if the initialization fails, that is, the Web component bound to the WebTag is not found.

setMessageEventHandler

void(* ArkWeb_WebMessagePortAPI::setMessageEventHandler) (const ArkWeb_WebMessagePortPtr webMessagePort, const char *webTag, ArkWeb_OnMessageEventHandler messageEventHandler, void *userData)

Description

Pointer to the callback used to set the HTML messages received.

Parameters

Name Description
webMessagePort Pointer to the message port.
webTag Name of a Web component.
messageEventHandler Callback used to handle messages.
userData User-defined data.

size

size_t ArkWeb_WebMessagePortAPI::size

Description

Size of the struct.

你可能感兴趣的鸿蒙文章

harmony 鸿蒙ArkWeb API Reference

harmony 鸿蒙ArkWeb_AnyNativeAPI

harmony 鸿蒙ArkWeb_ComponentAPI

harmony 鸿蒙ArkWeb_ControllerAPI

harmony 鸿蒙ArkWeb_CookieManagerAPI

harmony 鸿蒙ArkWeb_JavaScriptBridgeData

harmony 鸿蒙ArkWeb_JavaScriptObject

harmony 鸿蒙ArkWeb_JavaScriptValueAPI

harmony 鸿蒙ArkWeb_ProxyMethod

harmony 鸿蒙ArkWeb_ProxyMethodWithResult

0  赞