已合并
资料8分需求 #153287
wangsen1994创建于 7月2日
资料8分需求 #153287
已合并
共 18 个文件变更+518-434
| @@ -12,7 +12,7 @@ typedef struct CommonEvent_PublishInfo CommonEvent_PublishInfo | |||
| 12 | 12 | ||
| 13 | ## 概述 | 13 | ## 概述 |
| 14 | 14 | ||
| 15 | -发布公共事件时使用的公共事件属性对象。 | 15 | +发布公共事件时使用的公共事件属性对象。该对象封装了发布公共事件所需的各项属性配置,适用于应用需要发布自定义公共事件并指定发布参数的场景。 |
| 16 | 16 | ||
| 17 | **起始版本:** 18 | 17 | **起始版本:** 18 |
| 18 | 18 | ||
Mzh-cn/application-dev/reference/apis-basic-services-kit/capi-oh-commonevent-commonevent-rcvdata.md+1-1
| @@ -12,7 +12,7 @@ typedef struct CommonEvent_RcvData CommonEvent_RcvData | |||
| 12 | 12 | ||
| 13 | ## 概述 | 13 | ## 概述 |
| 14 | 14 | ||
| 15 | -提供CommonEvent_RcvData公共事件回调数据结构体声明。 | 15 | +提供公共事件回调数据结构体声明,当公共事件触发回调时,通过该结构体向开发者传递接收到的事件数据。 |
| 16 | 16 | ||
| 17 | **起始版本:** 12 | 17 | **起始版本:** 12 |
| 18 | 18 | ||
| @@ -12,7 +12,7 @@ typedef struct CommonEvent_SubscribeInfo CommonEvent_SubscribeInfo | |||
| 12 | 12 | ||
| 13 | ## 概述 | 13 | ## 概述 |
| 14 | 14 | ||
| 15 | -提供CommonEvent_SubscribeInfo订阅者信息结构体声明。 | 15 | +提供公共事件订阅者信息结构体声明。该结构体用于描述订阅者的配置信息,在调用创建订阅者接口时作为参数传入。 |
| 16 | 16 | ||
| 17 | **起始版本:** 12 | 17 | **起始版本:** 12 |
| 18 | 18 | ||
| @@ -8,7 +8,39 @@ | |||
| 8 | 8 | ||
| 9 | ## 概述 | 9 | ## 概述 |
| 10 | 10 | ||
| 11 | -定义公共事件订阅与退订API接口与枚举错误码。 | 11 | +本模块定义了发布、订阅/取消订阅公共事件、事件回调数据访问、有序事件控制等关键操作函数,以及错误码枚举与核心数据类型定义。 |
| 12 | + | ||
| 13 | +**API 组合使用关系说明:** | ||
| 14 | + | ||
| 15 | +本模块存在三条明确的API调用流程:订阅流程、发布流程、有序事件处理流程。 | ||
| 16 | + | ||
| 17 | +**组合一:订阅并处理公共事件** | ||
| 18 | + | ||
| 19 | +1. 通过`OH_CommonEvent_CreateSubscribeInfo`创建订阅者信息,声明需要订阅的事件名称,可选设置发布方权限与包名,用于过滤事件来源。 | ||
| 20 | +2. 通过`OH_CommonEvent_CreateSubscriber`创建订阅者并注册接收事件回调函数,再通过`OH_CommonEvent_Subscribe`发起事件订阅,订阅生效后即可在回调中等待事件投递。 | ||
| 21 | +3. 事件到达时,从回调参数`CommonEvent_RcvData`中获取事件名、code数据、data数据以及发布方包名等信息,然后进行业务逻辑处理。 | ||
| 22 | +4. 不再需要订阅时,调用`OH_CommonEvent_UnSubscribe`取消订阅,并释放相关资源。 | ||
| 23 | + | ||
| 24 | +**组合二:发布带附加信息的公共事件** | ||
| 25 | + | ||
| 26 | +1. 通过`OH_CommonEvent_CreatePublishInfo`创建公共事件属性对象,并按需设置code数据、data数据、订阅者包名、订阅者权限与附加信息等属性。 | ||
| 27 | +2. 通过`OH_CommonEvent_PublishWithInfo`发布携带属性的事件。 | ||
| 28 | + | ||
| 29 | +> 若无需附加属性,可直接调用便捷接口`OH_CommonEvent_Publish(event)`发布事件。 | ||
| 30 | + | ||
| 31 | +**组合三:有序公共事件处理** | ||
| 32 | + | ||
| 33 | +有序公共事件在订阅回调内通过订阅者句柄进行控制,订阅者句柄需在创建订阅者时保存,以便在回调中使用。 | ||
| 34 | + | ||
| 35 | +1. 发布公共事件时,通过`OH_CommonEvent_CreatePublishInfo(true)`创建有序事件属性,事件将按订阅者优先级依次投递。 | ||
| 36 | +2. 订阅者可在回调中通过`OH_CommonEvent_SetCodeToSubscriber`、`OH_CommonEvent_SetDataToSubscriber`设置传递给后续订阅者的code与data数据;通过`OH_CommonEvent_AbortCommonEvent`可标记事件为中止状态,终止其向后续订阅者投递。 | ||
| 37 | +3. 回调处理完成后,必须调用`OH_CommonEvent_FinishCommonEvent`结束处理,否则事件无法继续投递给后续订阅者。 | ||
| 38 | + | ||
| 39 | +需注意本模块遵循典型的"创建—使用—释放"生命周期: | ||
| 40 | + | ||
| 41 | +- **订阅侧对象**:`CommonEvent_SubscribeInfo`→`CommonEvent_Subscriber`。创建后订阅生效,取消订阅后需依次销毁订阅者和订阅信息,避免内存泄漏。 | ||
| 42 | +- **发布侧对象**:`CommonEvent_PublishInfo`与`CommonEvent_Parameters`。发布完成后需分别销毁,二者相互独立。 | ||
| 43 | + | ||
| 12 | 44 | ||
| 13 | **库:** libohcommonevent.so | 45 | **库:** libohcommonevent.so |
| 14 | 46 | ||
| @@ -35,7 +67,7 @@ | |||
| 35 | | 名称 | typedef关键字 | 描述 | | 67 | | 名称 | typedef关键字 | 描述 | |
| 36 | |----|------------|----| | 68 | |----|------------|----| |
| 37 | | void | CommonEvent_Subscriber | 提供CommonEvent_Subscriber订阅者声明。 | | 69 | | void | CommonEvent_Subscriber | 提供CommonEvent_Subscriber订阅者声明。 | |
| 38 | -| void | CommonEvent_Parameters | 提供CommonEvent_RcvData公共事件附加信息声明。 | | 70 | +| void | CommonEvent_Parameters | 提供CommonEvent_Parameters公共事件附加信息声明。 | |
| 39 | 71 | ||
| 40 | ### 枚举 | 72 | ### 枚举 |
| 41 | 73 | ||
| @@ -57,8 +89,8 @@ | |||
| 57 | | [CommonEvent_ErrCode OH_CommonEvent_Subscribe(const CommonEvent_Subscriber* subscriber)](#oh_commonevent_subscribe) | - | 订阅公共事件。 | | 89 | | [CommonEvent_ErrCode OH_CommonEvent_Subscribe(const CommonEvent_Subscriber* subscriber)](#oh_commonevent_subscribe) | - | 订阅公共事件。 | |
| 58 | | [CommonEvent_ErrCode OH_CommonEvent_UnSubscribe(const CommonEvent_Subscriber* subscriber)](#oh_commonevent_unsubscribe) | - | 退订公共事件。 | | 90 | | [CommonEvent_ErrCode OH_CommonEvent_UnSubscribe(const CommonEvent_Subscriber* subscriber)](#oh_commonevent_unsubscribe) | - | 退订公共事件。 | |
| 59 | | [const char* OH_CommonEvent_GetEventFromRcvData(const CommonEvent_RcvData* rcvData)](#oh_commonevent_geteventfromrcvdata) | - | 获取当前接收的公共事件名称。 | | 91 | | [const char* OH_CommonEvent_GetEventFromRcvData(const CommonEvent_RcvData* rcvData)](#oh_commonevent_geteventfromrcvdata) | - | 获取当前接收的公共事件名称。 | |
| 60 | -| [int32_t OH_CommonEvent_GetCodeFromRcvData(const CommonEvent_RcvData* rcvData)](#oh_commonevent_getcodefromrcvdata) | - | 获取接收到的公共事件数据,整数类型。 | | 92 | +| [int32_t OH_CommonEvent_GetCodeFromRcvData(const CommonEvent_RcvData* rcvData)](#oh_commonevent_getcodefromrcvdata) | - | 获取公共事件传递的Code数据,整数类型。 | |
| 61 | -| [const char* OH_CommonEvent_GetDataStrFromRcvData(const CommonEvent_RcvData* rcvData)](#oh_commonevent_getdatastrfromrcvdata) | - | 获取接收到的公共事件数据,字符串类型。 | | 93 | +| [const char* OH_CommonEvent_GetDataStrFromRcvData(const CommonEvent_RcvData* rcvData)](#oh_commonevent_getdatastrfromrcvdata) | - | 获取公共事件传递的数据,字符串类型。 | |
| 62 | | [const char* OH_CommonEvent_GetBundleNameFromRcvData(const CommonEvent_RcvData* rcvData)](#oh_commonevent_getbundlenamefromrcvdata) | - | 获取接收到的公共事件的包名称信息。 | | 94 | | [const char* OH_CommonEvent_GetBundleNameFromRcvData(const CommonEvent_RcvData* rcvData)](#oh_commonevent_getbundlenamefromrcvdata) | - | 获取接收到的公共事件的包名称信息。 | |
| 63 | | [const CommonEvent_Parameters* OH_CommonEvent_GetParametersFromRcvData(const CommonEvent_RcvData* rcvData)](#oh_commonevent_getparametersfromrcvdata) | - | 获取公共事件附加信息。 | | 95 | | [const CommonEvent_Parameters* OH_CommonEvent_GetParametersFromRcvData(const CommonEvent_RcvData* rcvData)](#oh_commonevent_getparametersfromrcvdata) | - | 获取公共事件附加信息。 | |
| 64 | | [CommonEvent_PublishInfo* OH_CommonEvent_CreatePublishInfo(bool ordered)](#oh_commonevent_createpublishinfo) | - | 创建公共事件属性对象。 | | 96 | | [CommonEvent_PublishInfo* OH_CommonEvent_CreatePublishInfo(bool ordered)](#oh_commonevent_createpublishinfo) | - | 创建公共事件属性对象。 | |
| @@ -124,10 +156,10 @@ enum CommonEvent_ErrCode | |||
| 124 | | COMMONEVENT_ERR_INVALID_PARAMETER = 401 | 参数错误。 | | 156 | | COMMONEVENT_ERR_INVALID_PARAMETER = 401 | 参数错误。 | |
| 125 | | COMMONEVENT_ERR_SENDING_LIMIT_EXCEEDED = 1500003| 事件发送频率过高。<br>**起始版本:** 20 | | 157 | | COMMONEVENT_ERR_SENDING_LIMIT_EXCEEDED = 1500003| 事件发送频率过高。<br>**起始版本:** 20 | |
| 126 | | COMMONEVENT_ERR_NOT_SYSTEM_SERVICE = 1500004 | 三方应用无法发送系统公共事件。 | | 158 | | COMMONEVENT_ERR_NOT_SYSTEM_SERVICE = 1500004 | 三方应用无法发送系统公共事件。 | |
| 127 | -| COMMONEVENT_ERR_SENDING_REQUEST_FAILED = 1500007 | IPC发送失败。 | | 159 | +| COMMONEVENT_ERR_SENDING_REQUEST_FAILED = 1500007 | IPC发送失败。| |
| 128 | | COMMONEVENT_ERR_INIT_UNDONE = 1500008 | 服务未初始化。 | | 160 | | COMMONEVENT_ERR_INIT_UNDONE = 1500008 | 服务未初始化。 | |
| 129 | | COMMONEVENT_ERR_OBTAIN_SYSTEM_PARAMS = 1500009 | 系统错误。 | | 161 | | COMMONEVENT_ERR_OBTAIN_SYSTEM_PARAMS = 1500009 | 系统错误。 | |
| 130 | -| COMMONEVENT_ERR_SUBSCRIBER_NUM_EXCEEDED = 1500010 | 订阅者数量超过限制。 | | 162 | +| COMMONEVENT_ERR_SUBSCRIBER_NUM_EXCEEDED = 1500010 | 进程内订阅者数量超过系统限制(200个)。 | |
| 131 | | COMMONEVENT_ERR_ALLOC_MEMORY_FAILED = 1500011 | 内存分配失败。 | | 163 | | COMMONEVENT_ERR_ALLOC_MEMORY_FAILED = 1500011 | 内存分配失败。 | |
| 132 | 164 | ||
| 133 | 165 | ||
| @@ -170,13 +202,13 @@ CommonEvent_SubscribeInfo* OH_CommonEvent_CreateSubscribeInfo(const char* events | |||
| 170 | | 参数项 | 描述 | | 202 | | 参数项 | 描述 | |
| 171 | | -- | -- | | 203 | | -- | -- | |
| 172 | | const char* events[] | 订阅的公共事件,实际订阅的公共事件数量为`eventsNum`与`events`数组长度的最小值。 | | 204 | | const char* events[] | 订阅的公共事件,实际订阅的公共事件数量为`eventsNum`与`events`数组长度的最小值。 | |
| 173 | -| int32_t eventsNum | 订阅的公共事件数量。 | | 205 | +| int32_t eventsNum | 订阅的公共事件数量,取值为`events`数组长度。 | |
| 174 | 206 | ||
| 175 | **返回:** | 207 | **返回:** |
| 176 | 208 | ||
| 177 | | 类型 | 说明 | | 209 | | 类型 | 说明 | |
| 178 | |--------------------------------| -- | | 210 | |--------------------------------| -- | |
| 179 | -| [CommonEvent_SubscribeInfo](capi-oh-commonevent-commonevent-subscribeinfo.md)* | 成功则返回订阅者信息,失败则返回NULL。 | | 211 | +| [CommonEvent_SubscribeInfo](capi-oh-commonevent-commonevent-subscribeinfo.md)* | 成功则返回订阅者信息,失败则返回NULL。 | |
| 180 | 212 | ||
| 181 | ### OH_CommonEvent_SetPublisherPermission() | 213 | ### OH_CommonEvent_SetPublisherPermission() |
| 182 | 214 | ||
| @@ -267,13 +299,13 @@ CommonEvent_Subscriber* OH_CommonEvent_CreateSubscriber(const CommonEvent_Subscr | |||
| 267 | | 参数项 | 描述 | | 299 | | 参数项 | 描述 | |
| 268 | |----------------------------------------------------------------------| -- | | 300 | |----------------------------------------------------------------------| -- | |
| 269 | | const [CommonEvent_SubscribeInfo](capi-oh-commonevent-commonevent-subscribeinfo.md)* info | 订阅者信息。 | | 301 | | const [CommonEvent_SubscribeInfo](capi-oh-commonevent-commonevent-subscribeinfo.md)* info | 订阅者信息。 | |
| 270 | -| [CommonEvent_ReceiveCallback](#commonevent_receivecallback) callback | 公共事件回调函数 | | 302 | +| [CommonEvent_ReceiveCallback](#commonevent_receivecallback) callback | 公共事件回调函数。 | |
| 271 | 303 | ||
| 272 | **返回:** | 304 | **返回:** |
| 273 | 305 | ||
| 274 | | 类型 | 说明 | | 306 | | 类型 | 说明 | |
| 275 | | -- | -- | | 307 | | -- | -- | |
| 276 | -| [CommonEvent_Subscriber](#变量)* | 成功则返回订阅者,失败则返回NULL。 | | 308 | +| [CommonEvent_Subscriber](#变量)* | 成功则返回订阅者,失败则返回NULL。 | |
| 277 | 309 | ||
| 278 | ### OH_CommonEvent_DestroySubscriber() | 310 | ### OH_CommonEvent_DestroySubscriber() |
| 279 | 311 | ||
| @@ -317,7 +349,7 @@ CommonEvent_ErrCode OH_CommonEvent_Subscribe(const CommonEvent_Subscriber* subsc | |||
| 317 | 349 | ||
| 318 | | 类型 | 说明 | | 350 | | 类型 | 说明 | |
| 319 | | -- | -- | | 351 | | -- | -- | |
| 320 | -| [CommonEvent_ErrCode](#commonevent_errcode) | 返回错误码。<br> 返回[COMMONEVENT_ERR_OK](capi-oh-commonevent-h.md#commonevent_errcode)表示成功。<br> 返回[COMMONEVENT_ERR_INVALID_PARAMETER](capi-oh-commonevent-h.md#commonevent_errcode)表示参数subscriber无效。<br> 返回[COMMONEVENT_ERR_SENDING_REQUEST_FAILED](capi-oh-commonevent-h.md#commonevent_errcode)表示IPC请求发送失败。<br> 返回[COMMONEVENT_ERR_INIT_UNDONE](capi-oh-commonevent-h.md#commonevent_errcode)表示公共事件服务未初始化。<br> 返回[COMMONEVENT_ERR_SUBSCRIBER_NUM_EXCEEDED](capi-oh-commonevent-h.md#commonevent_errcode)表示进程订阅者数量超过200个。<br> 返回[COMMONEVENT_ERR_ALLOC_MEMORY_FAILED](capi-oh-commonevent-h.md#commonevent_errcode)系统分配内存失败。 | | 352 | +| [CommonEvent_ErrCode](#commonevent_errcode) | 返回错误码。<br> 返回[COMMONEVENT_ERR_OK](capi-oh-commonevent-h.md#commonevent_errcode)表示成功。<br> 返回[COMMONEVENT_ERR_INVALID_PARAMETER](capi-oh-commonevent-h.md#commonevent_errcode)表示参数subscriber无效。<br> 返回[COMMONEVENT_ERR_SENDING_REQUEST_FAILED](capi-oh-commonevent-h.md#commonevent_errcode)表示IPC请求发送失败。<br> 返回[COMMONEVENT_ERR_INIT_UNDONE](capi-oh-commonevent-h.md#commonevent_errcode)表示公共事件服务未初始化。<br> 返回[COMMONEVENT_ERR_SUBSCRIBER_NUM_EXCEEDED](capi-oh-commonevent-h.md#commonevent_errcode)进程内订阅者数量超过系统限制(200个)。<br> 返回[COMMONEVENT_ERR_ALLOC_MEMORY_FAILED](capi-oh-commonevent-h.md#commonevent_errcode)表示系统分配内存失败。 | |
| 321 | 353 | ||
| 322 | ### OH_CommonEvent_UnSubscribe() | 354 | ### OH_CommonEvent_UnSubscribe() |
| 323 | 355 | ||
| @@ -352,7 +384,7 @@ const char* OH_CommonEvent_GetEventFromRcvData(const CommonEvent_RcvData* rcvDat | |||
| 352 | 384 | ||
| 353 | **描述** | 385 | **描述** |
| 354 | 386 | ||
| 355 | -获取当前接收的公共事件名称。 | 387 | +获取接收到的公共事件名称。 |
| 356 | 388 | ||
| 357 | **起始版本:** 12 | 389 | **起始版本:** 12 |
| 358 | 390 | ||
| @@ -367,7 +399,7 @@ const char* OH_CommonEvent_GetEventFromRcvData(const CommonEvent_RcvData* rcvDat | |||
| 367 | 399 | ||
| 368 | | 类型 | 说明 | | 400 | | 类型 | 说明 | |
| 369 | | -- | -- | | 401 | | -- | -- | |
| 370 | -| const char* | 返回事件名称。 | | 402 | +| const char* | 返回公共事件名称。 | |
| 371 | 403 | ||
| 372 | ### OH_CommonEvent_GetCodeFromRcvData() | 404 | ### OH_CommonEvent_GetCodeFromRcvData() |
| 373 | 405 | ||
| @@ -377,7 +409,7 @@ int32_t OH_CommonEvent_GetCodeFromRcvData(const CommonEvent_RcvData* rcvData) | |||
| 377 | 409 | ||
| 378 | **描述** | 410 | **描述** |
| 379 | 411 | ||
| 380 | -获取公共事件传递的数据,整数类型。 | 412 | +获取接收到的公共事件Code数据,整数类型。 |
| 381 | 413 | ||
| 382 | **起始版本:** 12 | 414 | **起始版本:** 12 |
| 383 | 415 | ||
| @@ -392,7 +424,7 @@ int32_t OH_CommonEvent_GetCodeFromRcvData(const CommonEvent_RcvData* rcvData) | |||
| 392 | 424 | ||
| 393 | | 类型 | 说明 | | 425 | | 类型 | 说明 | |
| 394 | | -- | -- | | 426 | | -- | -- | |
| 395 | -| int32_t | 返回公共事件传递的数据,整数类型。 | | 427 | +| int32_t | 返回接收到的公共事件Code数据,整数类型。 | |
| 396 | 428 | ||
| 397 | ### OH_CommonEvent_GetDataStrFromRcvData() | 429 | ### OH_CommonEvent_GetDataStrFromRcvData() |
| 398 | 430 | ||
| @@ -402,7 +434,7 @@ const char* OH_CommonEvent_GetDataStrFromRcvData(const CommonEvent_RcvData* rcvD | |||
| 402 | 434 | ||
| 403 | **描述** | 435 | **描述** |
| 404 | 436 | ||
| 405 | -获取公共事件传递的数据,字符串类型。 | 437 | +获取接收到的公共事件数据,字符串类型。 |
| 406 | 438 | ||
| 407 | **起始版本:** 12 | 439 | **起始版本:** 12 |
| 408 | 440 | ||
| @@ -417,7 +449,7 @@ const char* OH_CommonEvent_GetDataStrFromRcvData(const CommonEvent_RcvData* rcvD | |||
| 417 | 449 | ||
| 418 | | 类型 | 说明 | | 450 | | 类型 | 说明 | |
| 419 | | -- | -- | | 451 | | -- | -- | |
| 420 | -| const char* | 返回公共事件传递的数据,字符串类型。 | | 452 | +| const char* | 返回接收到的公共事件数据,字符串类型。 | |
| 421 | 453 | ||
| 422 | ### OH_CommonEvent_GetBundleNameFromRcvData() | 454 | ### OH_CommonEvent_GetBundleNameFromRcvData() |
| 423 | 455 | ||
| @@ -492,7 +524,7 @@ CommonEvent_PublishInfo* OH_CommonEvent_CreatePublishInfo(bool ordered) | |||
| 492 | 524 | ||
| 493 | | 类型 | 说明 | | 525 | | 类型 | 说明 | |
| 494 | |------------------------------| -- | | 526 | |------------------------------| -- | |
| 495 | -| [CommonEvent_PublishInfo](capi-oh-commonevent-commonevent-publishinfo.md)* | 创建的公共事件属性对象,创建失败时,返回null。 | | 527 | +| [CommonEvent_PublishInfo](capi-oh-commonevent-commonevent-publishinfo.md)* | 创建的公共事件属性对象,创建失败时,返回NULL。 | |
| 496 | 528 | ||
| 497 | ### OH_CommonEvent_DestroyPublishInfo() | 529 | ### OH_CommonEvent_DestroyPublishInfo() |
| 498 | 530 | ||
| @@ -558,7 +590,7 @@ CommonEvent_ErrCode OH_CommonEvent_SetPublishInfoPermissions(CommonEvent_Publish | |||
| 558 | | -- | -- | | 590 | | -- | -- | |
| 559 | | [CommonEvent_PublishInfo](capi-oh-commonevent-commonevent-publishinfo.md)* info | 公共事件属性对象。 | | 591 | | [CommonEvent_PublishInfo](capi-oh-commonevent-commonevent-publishinfo.md)* info | 公共事件属性对象。 | |
| 560 | | const char* permissions[] | 订阅者权限名称数组,生效数量为`num`与`permissions`数组长度的最小值。 | | 592 | | const char* permissions[] | 订阅者权限名称数组,生效数量为`num`与`permissions`数组长度的最小值。 | |
| 561 | -| int32_t num | 权限的数量。 | | 593 | +| int32_t num | 权限名称的数量,取值为`permissions`数组长度。 | |
| 562 | 594 | ||
| 563 | **返回:** | 595 | **返回:** |
| 564 | 596 | ||
| @@ -595,7 +627,7 @@ CommonEvent_ErrCode OH_CommonEvent_SetPublishInfoCode(CommonEvent_PublishInfo* i | |||
| 595 | ### OH_CommonEvent_SetPublishInfoData() | 627 | ### OH_CommonEvent_SetPublishInfoData() |
| 596 | 628 | ||
| 597 | ```c | 629 | ```c |
| 598 | -CommonEvent_ErrCode OH_CommonEvent_SetPublishInfoData(CommonEvent_PublishInfo* info,const char* data, size_t length) | 630 | +CommonEvent_ErrCode OH_CommonEvent_SetPublishInfoData(CommonEvent_PublishInfo* info, const char* data, size_t length) |
| 599 | ``` | 631 | ``` |
| 600 | 632 | ||
| 601 | **描述** | 633 | **描述** |
| @@ -610,8 +642,8 @@ CommonEvent_ErrCode OH_CommonEvent_SetPublishInfoData(CommonEvent_PublishInfo* i | |||
| 610 | | 参数项 | 描述 | | 642 | | 参数项 | 描述 | |
| 611 | | -- | -- | | 643 | | -- | -- | |
| 612 | | [CommonEvent_PublishInfo](capi-oh-commonevent-commonevent-publishinfo.md)* info | 公共事件属性对象。 | | 644 | | [CommonEvent_PublishInfo](capi-oh-commonevent-commonevent-publishinfo.md)* info | 公共事件属性对象。 | |
| 613 | -| const char* data | 公共事件传递的数据,字符串类型,实际有效数据长度为`length`和`data`字符串长度的最小值。 | | 645 | +| const char* data | 公共事件传递的数据,字符串类型,实际有效数据长度为`length`与`data`字符串长度的最小值。 | |
| 614 | -| size_t length | 结果数据的长度。 | | 646 | +| size_t length | 结果数据的长度,取值为`data`数据字符串长度。 | |
| 615 | 647 | ||
| 616 | **返回:** | 648 | **返回:** |
| 617 | 649 | ||
| @@ -637,7 +669,7 @@ CommonEvent_ErrCode OH_CommonEvent_SetPublishInfoParameters(CommonEvent_PublishI | |||
| 637 | | 参数项 | 描述 | | 669 | | 参数项 | 描述 | |
| 638 | | -- | -- | | 670 | | -- | -- | |
| 639 | | [CommonEvent_PublishInfo](capi-oh-commonevent-commonevent-publishinfo.md)* info | 公共事件属性对象。 | | 671 | | [CommonEvent_PublishInfo](capi-oh-commonevent-commonevent-publishinfo.md)* info | 公共事件属性对象。 | |
| 640 | -| CommonEvent_Parameters* param | 设置的附加信息。 | | 672 | +| [CommonEvent_Parameters](#变量)* param | 设置的附加信息。 | |
| 641 | 673 | ||
| 642 | **返回:** | 674 | **返回:** |
| 643 | 675 | ||
| @@ -661,7 +693,7 @@ CommonEvent_Parameters* OH_CommonEvent_CreateParameters() | |||
| 661 | 693 | ||
| 662 | | 类型 | 说明 | | 694 | | 类型 | 说明 | |
| 663 | | -- | -- | | 695 | | -- | -- | |
| 664 | -| [CommonEvent_Parameters](#变量)* | 返回公共事件附加信息,创建失败时,返回null。 | | 696 | +| [CommonEvent_Parameters](#变量)* | 返回公共事件附加信息,创建失败时,返回NULL。 | |
| 665 | 697 | ||
| 666 | ### OH_CommonEvent_DestroyParameters() | 698 | ### OH_CommonEvent_DestroyParameters() |
| 667 | 699 | ||
| @@ -727,7 +759,7 @@ int OH_CommonEvent_GetIntFromParameters(const CommonEvent_Parameters* para, cons | |||
| 727 | | -- | -- | | 759 | | -- | -- | |
| 728 | | const [CommonEvent_Parameters](#变量)* para | 公共事件附加信息。 | | 760 | | const [CommonEvent_Parameters](#变量)* para | 公共事件附加信息。 | |
| 729 | | const char* key | 数据键。 | | 761 | | const char* key | 数据键。 | |
| 730 | -| const int defaultValue | 默认值。 | | 762 | +| const int defaultValue | 默认值,当指定key不存在时返回此默认值。 | |
| 731 | 763 | ||
| 732 | **返回:** | 764 | **返回:** |
| 733 | 765 | ||
| @@ -781,7 +813,7 @@ int32_t OH_CommonEvent_GetIntArrayFromParameters(const CommonEvent_Parameters* p | |||
| 781 | | -- | -- | | 813 | | -- | -- | |
| 782 | | const [CommonEvent_Parameters](#变量)* para | 公共事件附加信息。 | | 814 | | const [CommonEvent_Parameters](#变量)* para | 公共事件附加信息。 | |
| 783 | | const char* key | 数据键。 | | 815 | | const char* key | 数据键。 | |
| 784 | -| int** array | 查询的数组。 | | 816 | +| int** array | 输出参数,用于接收查询到的int数组数据。该数组内存由函数内部分配,调用者无需预先分配。 | |
| 785 | 817 | ||
| 786 | **返回:** | 818 | **返回:** |
| 787 | 819 | ||
| @@ -836,7 +868,7 @@ long OH_CommonEvent_GetLongFromParameters(const CommonEvent_Parameters* para, co | |||
| 836 | | -- | -- | | 868 | | -- | -- | |
| 837 | | const [CommonEvent_Parameters](#变量)* para | 公共事件附加信息。 | | 869 | | const [CommonEvent_Parameters](#变量)* para | 公共事件附加信息。 | |
| 838 | | const char* key | 数据键。 | | 870 | | const char* key | 数据键。 | |
| 839 | -| const long defaultValue | 默认值。 | | 871 | +| const long defaultValue | 默认值,当指定key不存在时返回此默认值。 | |
| 840 | 872 | ||
| 841 | **返回:** | 873 | **返回:** |
| 842 | 874 | ||
| @@ -890,7 +922,7 @@ int32_t OH_CommonEvent_GetLongArrayFromParameters(const CommonEvent_Parameters* | |||
| 890 | | -- | -- | | 922 | | -- | -- | |
| 891 | | const [CommonEvent_Parameters](#变量)* para | 公共事件附加信息。 | | 923 | | const [CommonEvent_Parameters](#变量)* para | 公共事件附加信息。 | |
| 892 | | const char* key | 数据键。 | | 924 | | const char* key | 数据键。 | |
| 893 | -| long** array | 查询的数组。 | | 925 | +| long** array | 输出参数,用于接收查询到的long数组数据。该数组内存由函数内部分配,调用者无需预先分配。 | |
| 894 | 926 | ||
| 895 | **返回:** | 927 | **返回:** |
| 896 | 928 | ||
| @@ -945,7 +977,7 @@ bool OH_CommonEvent_GetBoolFromParameters(const CommonEvent_Parameters* para, co | |||
| 945 | | -- | -- | | 977 | | -- | -- | |
| 946 | | const [CommonEvent_Parameters](#变量)* para | 公共事件附加信息。 | | 978 | | const [CommonEvent_Parameters](#变量)* para | 公共事件附加信息。 | |
| 947 | | const char* key | 数据键。 | | 979 | | const char* key | 数据键。 | |
| 948 | -| const bool defaultValue | 默认值。 | | 980 | +| const bool defaultValue | 默认值,当指定key不存在时返回此默认值。 | |
| 949 | 981 | ||
| 950 | **返回:** | 982 | **返回:** |
| 951 | 983 | ||
| @@ -999,7 +1031,7 @@ int32_t OH_CommonEvent_GetBoolArrayFromParameters(const CommonEvent_Parameters* | |||
| 999 | | -- | -- | | 1031 | | -- | -- | |
| 1000 | | const [CommonEvent_Parameters](#变量)* para | 公共事件附加信息。 | | 1032 | | const [CommonEvent_Parameters](#变量)* para | 公共事件附加信息。 | |
| 1001 | | const char* key | 数据键。 | | 1033 | | const char* key | 数据键。 | |
| 1002 | -| bool** array | 查询的数组。 | | 1034 | +| bool** array | 输出参数,用于接收查询到的bool数组数据。该数组内存由函数内部分配,调用者无需预先分配。 | |
| 1003 | 1035 | ||
| 1004 | **返回:** | 1036 | **返回:** |
| 1005 | 1037 | ||
| @@ -1054,7 +1086,7 @@ char OH_CommonEvent_GetCharFromParameters(const CommonEvent_Parameters* para, co | |||
| 1054 | | -- | -- | | 1086 | | -- | -- | |
| 1055 | | const [CommonEvent_Parameters](#变量)* para | 公共事件附加信息。 | | 1087 | | const [CommonEvent_Parameters](#变量)* para | 公共事件附加信息。 | |
| 1056 | | const char* key | 数据键。 | | 1088 | | const char* key | 数据键。 | |
| 1057 | -| const char defaultValue | 默认值。 | | 1089 | +| const char defaultValue | 默认值,当指定key不存在时返回此默认值。 | |
| 1058 | 1090 | ||
| 1059 | **返回:** | 1091 | **返回:** |
| 1060 | 1092 | ||
| @@ -1108,7 +1140,7 @@ int32_t OH_CommonEvent_GetCharArrayFromParameters(const CommonEvent_Parameters* | |||
| 1108 | | -- | -- | | 1140 | | -- | -- | |
| 1109 | | const [CommonEvent_Parameters](#变量)* para | 公共事件附加信息。 | | 1141 | | const [CommonEvent_Parameters](#变量)* para | 公共事件附加信息。 | |
| 1110 | | const char* key | 数据键。 | | 1142 | | const char* key | 数据键。 | |
| 1111 | -| char** array | 查询的数组。 | | 1143 | +| char** array | 输出参数,用于接收查询到的char数组数据。该数组内存由函数内部分配,调用者无需预先分配。 | |
| 1112 | 1144 | ||
| 1113 | **返回:** | 1145 | **返回:** |
| 1114 | 1146 | ||
| @@ -1147,7 +1179,7 @@ CommonEvent_ErrCode OH_CommonEvent_SetCharArrayToParameters(CommonEvent_Paramete | |||
| 1147 | ### OH_CommonEvent_GetDoubleFromParameters() | 1179 | ### OH_CommonEvent_GetDoubleFromParameters() |
| 1148 | 1180 | ||
| 1149 | ```c | 1181 | ```c |
| 1150 | -double OH_CommonEvent_GetDoubleFromParameters(const CommonEvent_Parameters* para, const char* key,const double defaultValue) | 1182 | +double OH_CommonEvent_GetDoubleFromParameters(const CommonEvent_Parameters* para, const char* key, const double defaultValue) |
| 1151 | ``` | 1183 | ``` |
| 1152 | 1184 | ||
| 1153 | **描述** | 1185 | **描述** |
| @@ -1163,7 +1195,7 @@ double OH_CommonEvent_GetDoubleFromParameters(const CommonEvent_Parameters* para | |||
| 1163 | | -- | -- | | 1195 | | -- | -- | |
| 1164 | | const [CommonEvent_Parameters](#变量)* para | 公共事件附加信息。 | | 1196 | | const [CommonEvent_Parameters](#变量)* para | 公共事件附加信息。 | |
| 1165 | | const char* key | 数据键。 | | 1197 | | const char* key | 数据键。 | |
| 1166 | -| const double defaultValue | 默认值。 | | 1198 | +| const double defaultValue | 默认值,当指定key不存在时返回此默认值。 | |
| 1167 | 1199 | ||
| 1168 | **返回:** | 1200 | **返回:** |
| 1169 | 1201 | ||
| @@ -1217,7 +1249,7 @@ int32_t OH_CommonEvent_GetDoubleArrayFromParameters(const CommonEvent_Parameters | |||
| 1217 | | -- | -- | | 1249 | | -- | -- | |
| 1218 | | const [CommonEvent_Parameters](#变量)* para | 公共事件附加信息。 | | 1250 | | const [CommonEvent_Parameters](#变量)* para | 公共事件附加信息。 | |
| 1219 | | const char* key | 数据键。 | | 1251 | | const char* key | 数据键。 | |
| 1220 | -| double** array | 查询的数组。 | | 1252 | +| double** array | 输出参数,用于接收查询到的double数组数据。该数组内存由函数内部分配,调用者无需预先分配。 | |
| 1221 | 1253 | ||
| 1222 | **返回:** | 1254 | **返回:** |
| 1223 | 1255 | ||
| @@ -1503,7 +1535,7 @@ const char* OH_CommonEvent_GetDataFromSubscriber(const CommonEvent_Subscriber* s | |||
| 1503 | 1535 | ||
| 1504 | | 类型 | 说明 | | 1536 | | 类型 | 说明 | |
| 1505 | | -- | -- | | 1537 | | -- | -- | |
| 1506 | -| const char* | 返回有序公共事件传递的数据,字符串类型,无法获取时返回null。 | | 1538 | +| const char* | 返回有序公共事件传递的数据,字符串类型,无法获取时返回NULL。 | |
| 1507 | 1539 | ||
| 1508 | ### OH_CommonEvent_SetDataToSubscriber() | 1540 | ### OH_CommonEvent_SetDataToSubscriber() |
| 1509 | 1541 | ||
| @@ -1523,8 +1555,8 @@ bool OH_CommonEvent_SetDataToSubscriber(CommonEvent_Subscriber* subscriber, cons | |||
| 1523 | | 参数项 | 描述 | | 1555 | | 参数项 | 描述 | |
| 1524 | | -- | -- | | 1556 | | -- | -- | |
| 1525 | | [CommonEvent_Subscriber](#变量)* subscriber | 公共事件的订阅者对象。 | | 1557 | | [CommonEvent_Subscriber](#变量)* subscriber | 公共事件的订阅者对象。 | |
| 1526 | -| const char* data | 有序公共事件传递的数据,字符串类型,实际有效数据长度为`length`与`data`字符串长度的较小值。 | | 1558 | +| const char* data | 有序公共事件传递的数据,字符串类型,实际有效数据长度为`length`与`data`字符串长度的最小值。 | |
| 1527 | -| size_t length | 数据的长度。 | | 1559 | +| size_t length | 传递的数据字节长度,取值为`data`字符串长度。 | |
| 1528 | 1560 | ||
| 1529 | **返回:** | 1561 | **返回:** |
| 1530 | 1562 | ||
| @@ -8,7 +8,18 @@ | |||
| 8 | 8 | ||
| 9 | ## 概述 | 9 | ## 概述 |
| 10 | 10 | ||
| 11 | -提供订阅与退订公共事件的能力。 | 11 | +本模块是公共事件服务(Common Event Service)对外开放的 C 语言 API 模块,为应用提供基于"发布—订阅"模型的跨进程事件通信能力:发布者发布一个公共事件后,系统根据事件名称将事件投递给所有已订阅该事件的订阅者,从而实现应用之间、应用与系统之间的解耦通信。 |
| 12 | + | ||
| 13 | +主要提供以下能力: | ||
| 14 | + | ||
| 15 | +- **事件订阅与取消订阅**:创建订阅信息、创建订阅者、订阅/取消订阅指定公共事件,并在事件到达时通过回调接收事件数据。 | ||
| 16 | +- **事件发布**:发布公共事件,支持设置有序/无序、权限、应用包名称、code数据、data数据及附加信息等发布属性。 | ||
| 17 | +- **事件数据访问**:从回调数据中获取事件名、结果码、结果数据、发布者应用包名称及附加信息(Parameters,KV 键值对,支持 int/long/bool/char/double 及其数组类型的读写)。 | ||
| 18 | +- **有序公共事件控制**:对有序公共事件进行终止、清除终止状态、获取/设置结果码与结果数据、完成事件等控制。 | ||
| 19 | +- **系统公共事件常量**:提供系统已定义的公共事件名称常量(如电量变化、屏幕亮灭、Wi-Fi 状态、USB 状态等),便于订阅系统状态变化。 | ||
| 20 | +- **错误码**:统一枚举操作过程中可能返回的错误码。 | ||
| 21 | + | ||
| 22 | +**适用场景**:当应用需要感知系统状态变化(如电量、屏幕、网络、Wi-Fi、USB、包安装等)或需要在多应用间广播业务消息时,可使用本模块订阅或发布公共事件。 | ||
| 12 | 23 | ||
| 13 | **系统能力:** SystemCapability.Notification.CommonEvent | 24 | **系统能力:** SystemCapability.Notification.CommonEvent |
| 14 | 25 | ||
| @@ -18,5 +29,5 @@ | |||
| 18 | 29 | ||
| 19 | | 名称 | 描述 | | 30 | | 名称 | 描述 | |
| 20 | | -- | -- | | 31 | | -- | -- | |
| 21 | -| [oh_commonevent.h](capi-oh-commonevent-h.md) | 定义公共事件订阅与退订API接口与枚举错误码。 | | 32 | +| [oh_commonevent.h](capi-oh-commonevent-h.md) | 提供订阅、取消订阅、发布、事件数据访问、附加信息读写、有序事件控制等全部操作函数,以及错误码枚举与核心数据类型定义。 | |
| 22 | -| [oh_commonevent_support.h](capi-oh-commonevent-support-h.md) | 提供系统定义的公共事件常量。 | | 33 | +| [oh_commonevent_support.h](capi-oh-commonevent-support-h.md) | 提供系统预定义的公共事件名称常量(如 `COMMON_EVENT_BATTERY_CHANGED`、`COMMON_EVENT_SCREEN_ON` 等),供订阅时引用,本身不提供函数。 | |
| @@ -572,7 +572,7 @@ datashare服务启动完成后,将会触发事件通知服务发布该系统 | |||
| 572 | 572 | ||
| 573 | > 说明: | 573 | > 说明: |
| 574 | > | 574 | > |
| 575 | - > 从API Version 10开始废弃,替代接口为[COMMON_EVENT_SCREEN_UNLOCKED](#common_event_screen_unlocked)。 | 575 | + > 从API version 9 开始支持,从API version 10 开始废弃,建议使用[COMMON_EVENT_SCREEN_UNLOCKED](#common_event_screen_unlocked)代替。 |
| 576 | 576 | ||
| 577 | **系统能力:** SystemCapability.Notification.CommonEvent | 577 | **系统能力:** SystemCapability.Notification.CommonEvent |
| 578 | 578 | ||
| @@ -1355,7 +1355,7 @@ Multimodalinput Kit面向应用发布如下系统公共事件。 | |||
| 1355 | 1355 | ||
| 1356 | **系统能力:** SystemCapability.Notification.CommonEvent | 1356 | **系统能力:** SystemCapability.Notification.CommonEvent |
| 1357 | 1357 | ||
| 1358 | -**取值:** "usual.event.TABLET_MODE_CHANGED " | 1358 | +**取值:** "usual.event.TABLET_MODE_CHANGED" |
| 1359 | 1359 | ||
| 1360 | ### COMMON_EVENT_LID_STATE_CHANGED<sup>23+</sup> | 1360 | ### COMMON_EVENT_LID_STATE_CHANGED<sup>23+</sup> |
| 1361 | 1361 | ||
| @@ -1817,7 +1817,7 @@ Multimodalinput Kit面向应用发布如下系统公共事件。 | |||
| 1817 | 1817 | ||
| 1818 | **订阅者所需权限:** 无 | 1818 | **订阅者所需权限:** 无 |
| 1819 | 1819 | ||
| 1820 | -**取值:** "usual.event.USER_FOREGROUND“ | 1820 | +**取值:** "usual.event.USER_FOREGROUND" |
| 1821 | 1821 | ||
| 1822 | 1822 | ||
| 1823 | 1823 | ||
| @@ -18,17 +18,17 @@ The action field in the want parameter is null. | |||
| 18 | 18 | ||
| 19 | **错误描述** | 19 | **错误描述** |
| 20 | 20 | ||
| 21 | -发送事件的`want`中的`Action`属性为空时系统会产生此错误码。 | 21 | +发送公共事件的`want`中的`action`属性为空时系统会产生此错误码。 |
| 22 | 22 | ||
| 23 | **可能原因** | 23 | **可能原因** |
| 24 | 24 | ||
| 25 | -发送事件的`want`中的`Action`属性为空。 | 25 | +发送公共事件的`want`中的`action`属性为空。 |
| 26 | 26 | ||
| 27 | **处理步骤** | 27 | **处理步骤** |
| 28 | 28 | ||
| 29 | -检查传入`want`的`Action`属性是否为空。 | 29 | +检查传入`want`的`action`属性是否为空。 |
| 30 | 30 | ||
| 31 | -## 1500002 沙箱应用无法发送公共事件 | 31 | +## 1500002 沙箱应用无法发送公共事件 |
| 32 | 32 | ||
| 33 | **错误信息** | 33 | **错误信息** |
| 34 | 34 | ||
| @@ -40,13 +40,13 @@ A sandbox application cannot send common events. | |||
| 40 | 40 | ||
| 41 | **可能原因** | 41 | **可能原因** |
| 42 | 42 | ||
| 43 | -事件发送方应用为沙箱应用,发送事件会被拦截。 | 43 | +事件发送方应用为沙箱应用,发送公共事件会被拦截。 |
| 44 | 44 | ||
| 45 | **处理步骤** | 45 | **处理步骤** |
| 46 | 46 | ||
| 47 | -沙箱应用无法发送公共事件,发送公共事件前确认是否为沙箱应用。 | 47 | +确认发送公共事件的应用是否为沙箱应用。 |
| 48 | 48 | ||
| 49 | -## 1500003 事件发送频率过高 | 49 | +## 1500003 公共事件发送频率过高 |
| 50 | 50 | ||
| 51 | **错误信息** | 51 | **错误信息** |
| 52 | 52 | ||
| @@ -54,17 +54,17 @@ The common event sending frequency too high. | |||
| 54 | 54 | ||
| 55 | **错误描述** | 55 | **错误描述** |
| 56 | 56 | ||
| 57 | -应用发送事件过于频繁。 | 57 | +应用发送公共事件的频率超过系统限制。 |
| 58 | 58 | ||
| 59 | **可能原因** | 59 | **可能原因** |
| 60 | 60 | ||
| 61 | -短时间内应用发送过多事件。 | 61 | +短时间内应用发送事件数量超过系统频率限制,触发频率控制。 |
| 62 | 62 | ||
| 63 | **处理步骤** | 63 | **处理步骤** |
| 64 | 64 | ||
| 65 | -检查应用是否过于频繁地发送事件。 | 65 | +检查应用是否过于频繁地发送公共事件,如过于频繁,请降低事件发送频率或增加发送间隔后重新尝试。 |
| 66 | 66 | ||
| 67 | -## 1500004 无法发送系统公共事件 | 67 | +## 1500004 无法发送系统公共事件 |
| 68 | 68 | ||
| 69 | **错误信息** | 69 | **错误信息** |
| 70 | 70 | ||
| @@ -72,7 +72,7 @@ A third-party application cannot send system common events. | |||
| 72 | 72 | ||
| 73 | **错误描述** | 73 | **错误描述** |
| 74 | 74 | ||
| 75 | -当前应用无法发送系统公共事件。 | 75 | +第三方应用无法发送系统公共事件。 |
| 76 | 76 | ||
| 77 | **可能原因** | 77 | **可能原因** |
| 78 | 78 | ||
| @@ -82,7 +82,7 @@ A third-party application cannot send system common events. | |||
| 82 | 82 | ||
| 83 | 确认当前应用是否为系统应用,或当前服务是否为系统服务。 | 83 | 确认当前应用是否为系统应用,或当前服务是否为系统服务。 |
| 84 | 84 | ||
| 85 | -## 1500005 未找到订阅者 | 85 | +## 1500005 未找到订阅者 |
| 86 | 86 | ||
| 87 | **错误信息** | 87 | **错误信息** |
| 88 | 88 | ||
| @@ -94,13 +94,13 @@ The subscriber is not found. | |||
| 94 | 94 | ||
| 95 | **可能原因** | 95 | **可能原因** |
| 96 | 96 | ||
| 97 | -订阅者被删除。 | 97 | +订阅者已取消订阅被系统删除。 |
| 98 | 98 | ||
| 99 | **处理步骤** | 99 | **处理步骤** |
| 100 | 100 | ||
| 101 | 检查是否有重复取消订阅。 | 101 | 检查是否有重复取消订阅。 |
| 102 | 102 | ||
| 103 | -## 1500006 无效userId | 103 | +## 1500006 无效userId |
| 104 | 104 | ||
| 105 | **错误信息** | 105 | **错误信息** |
| 106 | 106 | ||
| @@ -112,14 +112,14 @@ Invalid userId. | |||
| 112 | 112 | ||
| 113 | **可能原因** | 113 | **可能原因** |
| 114 | 114 | ||
| 115 | -和系统`userId`不一致或不是系统应用或系统服务进程。 | 115 | +和系统userId不一致或不是系统应用或系统服务进程。 |
| 116 | 116 | ||
| 117 | **处理步骤** | 117 | **处理步骤** |
| 118 | 118 | ||
| 119 | -1. 检查当前`userId`是否和系统`userId`一致。 | 119 | +1. 检查当前userId是否和系统userId一致。 |
| 120 | 2. 检查当前应用是否为系统应用或系统服务。 | 120 | 2. 检查当前应用是否为系统应用或系统服务。 |
| 121 | 121 | ||
| 122 | -## 1500007 IPC请求发送失败 | 122 | +## 1500007 IPC请求发送失败 |
| 123 | 123 | ||
| 124 | **错误信息** | 124 | **错误信息** |
| 125 | 125 | ||
| @@ -131,13 +131,13 @@ Failed to send the message to the common event service. | |||
| 131 | 131 | ||
| 132 | **可能原因** | 132 | **可能原因** |
| 133 | 133 | ||
| 134 | -没有成功创建连接对象。 | 134 | +短时间内频繁建立IPC连接导致系统资源紧张,未能成功创建连接对象。 |
| 135 | 135 | ||
| 136 | **处理步骤** | 136 | **处理步骤** |
| 137 | 137 | ||
| 138 | -请勿频繁建立链接,稍后重新尝试。 | 138 | +请勿频繁建立连接,稍后重新尝试。 |
| 139 | 139 | ||
| 140 | -## 1500008 公共事件服务端初始化失败 | 140 | +## 1500008 公共事件服务端初始化失败 |
| 141 | 141 | ||
| 142 | **错误信息** | 142 | **错误信息** |
| 143 | 143 | ||
| @@ -145,17 +145,17 @@ Failed to initialize the common event service. | |||
| 145 | 145 | ||
| 146 | **错误描述** | 146 | **错误描述** |
| 147 | 147 | ||
| 148 | -服务端发生错误。 | 148 | +公共事件服务端在初始化过程中发生错误。 |
| 149 | 149 | ||
| 150 | **可能原因** | 150 | **可能原因** |
| 151 | 151 | ||
| 152 | -服务端处理数据时发现业务异常。 | 152 | +服务端初始化处理数据时发现业务异常。 |
| 153 | 153 | ||
| 154 | **处理步骤** | 154 | **处理步骤** |
| 155 | 155 | ||
| 156 | 稍后重新尝试。 | 156 | 稍后重新尝试。 |
| 157 | 157 | ||
| 158 | -## 1500009 获取系统参数失败 | 158 | +## 1500009 获取系统参数失败 |
| 159 | 159 | ||
| 160 | **错误信息** | 160 | **错误信息** |
| 161 | 161 | ||
| @@ -173,7 +173,7 @@ Failed to obtain system parameters. | |||
| 173 | 173 | ||
| 174 | 稍后重新尝试。 | 174 | 稍后重新尝试。 |
| 175 | 175 | ||
| 176 | -## 1500010 订阅者数量超限 | 176 | +## 1500010 订阅者数量超限 |
| 177 | 177 | ||
| 178 | **错误信息** | 178 | **错误信息** |
| 179 | 179 | ||
| @@ -185,8 +185,8 @@ The count of subscriber exceed system specification. | |||
| 185 | 185 | ||
| 186 | **可能原因** | 186 | **可能原因** |
| 187 | 187 | ||
| 188 | -订阅者不再使用时未及时取消订阅。公共事件限制每个进程最多订阅200个订阅者,进程内所有业务共享订阅者数量。 | 188 | +订阅者不再使用时未取消订阅。公共事件限制每个进程最多订阅200个订阅者,进程内所有业务共享订阅者数量。 |
| 189 | 189 | ||
| 190 | **处理步骤** | 190 | **处理步骤** |
| 191 | 191 | ||
| 192 | -检查应用内是否存在订阅者未取消订阅,如存在则取消订阅后重新尝试;不存在请稍后重新尝试。 | 192 | +检查应用内是否存在订阅者未取消订阅,如存在则取消订阅后重新尝试;不存在请稍后重新尝试。 |
| @@ -26,7 +26,7 @@ import { StaticSubscriberExtensionContext } from '@kit.BasicServicesKit'; | |||
| 26 | 26 | ||
| 27 | ## 使用说明 | 27 | ## 使用说明 |
| 28 | 28 | ||
| 29 | -在使用StaticSubscriberExtensionContext的功能前,需要通过StaticSubscriberExtensionAbility获取。 | 29 | +在使用StaticSubscriberExtensionContext的功能前,需要通过StaticSubscriberExtensionAbility获取该上下文。 |
| 30 | 30 | ||
| 31 | ```ts | 31 | ```ts |
| 32 | import { StaticSubscriberExtensionAbility, StaticSubscriberExtensionContext } from '@kit.BasicServicesKit'; | 32 | import { StaticSubscriberExtensionAbility, StaticSubscriberExtensionContext } from '@kit.BasicServicesKit'; |
| @@ -36,11 +36,7 @@ import { StaticSubscriberExtensionAbility, StaticSubscriberExtensionContext } fr | |||
| 36 | 36 | ||
| 37 | startAbility(want: Want, callback: AsyncCallback<void>): void | 37 | startAbility(want: Want, callback: AsyncCallback<void>): void |
| 38 | 38 | ||
| 39 | -拉起一个静态订阅所属的同应用的Ability。使用callback异步回调。 | 39 | +拉起与静态订阅同属一个应用的Ability。使用callback异步回调。 |
| 40 | - | ||
| 41 | -使用规则: | ||
| 42 | - - 调用方应用位于后台时,使用该接口启动Ability需申请`ohos.permission.START_ABILITIES_FROM_BACKGROUND`权限 | ||
| 43 | - - 跨应用场景下,目标Ability的visible属性若配置为false,调用方应用需申请`ohos.permission.START_INVISIBLE_ABILITY`权限 | ||
| 44 | 40 | ||
| 45 | **需要权限**:ohos.permission.START_ABILITIES_FROM_BACKGROUND | 41 | **需要权限**:ohos.permission.START_ABILITIES_FROM_BACKGROUND |
| 46 | 42 | ||
| @@ -52,8 +48,8 @@ startAbility(want: Want, callback: AsyncCallback<void>): void | |||
| 52 | 48 | ||
| 53 | | 参数名 | 类型 | 必填 | 说明 | | 49 | | 参数名 | 类型 | 必填 | 说明 | |
| 54 | | -------- | ----------------------------------- | ---- | -------------------------- | | 50 | | -------- | ----------------------------------- | ---- | -------------------------- | |
| 55 | -| want | [Want](../apis-ability-kit/js-apis-wantAgent.md) | 是 | 启动Ability的want信息。 | | 51 | +| want | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | 是 | 启动Ability的want信息。 | |
| 56 | -| callback | AsyncCallback<void> | 是 | callback形式返回启动结果。 | | 52 | +| callback | AsyncCallback<void> | 是 | 回调函数,用于接收启动结果。 | |
| 57 | 53 | ||
| 58 | **错误码:** | 54 | **错误码:** |
| 59 | 55 | ||
| @@ -85,8 +81,8 @@ startAbility(want: Want, callback: AsyncCallback<void>): void | |||
| 85 | import { Want } from '@kit.AbilityKit'; | 81 | import { Want } from '@kit.AbilityKit'; |
| 86 | 82 | ||
| 87 | let want: Want = { | 83 | let want: Want = { |
| 88 | - bundleName: "com.example.myapp", | 84 | + bundleName: 'com.example.myapp', |
| 89 | - abilityName: "MyAbility" | 85 | + abilityName: 'MyAbility' |
| 90 | }; | 86 | }; |
| 91 | 87 | ||
| 92 | class MyStaticSubscriberExtensionAbility extends StaticSubscriberExtensionAbility { | 88 | class MyStaticSubscriberExtensionAbility extends StaticSubscriberExtensionAbility { |
| @@ -97,7 +93,7 @@ startAbility(want: Want, callback: AsyncCallback<void>): void | |||
| 97 | this.context.startAbility(want, (error: BusinessError) => { | 93 | this.context.startAbility(want, (error: BusinessError) => { |
| 98 | if (error) { | 94 | if (error) { |
| 99 | // 处理业务逻辑错误 | 95 | // 处理业务逻辑错误 |
| 100 | - console.error(`startAbility failed, error.code: ${JSON.stringify(error.code)}, error.message: ${JSON.stringify(error.message)}.`); | 96 | + console.error(`startAbility failed, error.code: ${error.code}, error.message: ${error.message}.`); |
| 101 | return; | 97 | return; |
| 102 | } | 98 | } |
| 103 | // 执行正常业务 | 99 | // 执行正常业务 |
| @@ -117,11 +113,7 @@ startAbility(want: Want, callback: AsyncCallback<void>): void | |||
| 117 | 113 | ||
| 118 | startAbility(want: Want): Promise<void> | 114 | startAbility(want: Want): Promise<void> |
| 119 | 115 | ||
| 120 | -拉起一个静态订阅所属的同应用的Ability。使用Promise异步回调。 | 116 | +拉起与静态订阅同属一个应用的Ability。使用Promise异步回调。 |
| 121 | - | ||
| 122 | -使用规则: | ||
| 123 | - - 调用方应用位于后台时,使用该接口启动Ability需申请`ohos.permission.START_ABILITIES_FROM_BACKGROUND`权限 | ||
| 124 | - - 跨应用场景下,目标Ability的visible属性若配置为false,调用方应用需申请`ohos.permission.START_INVISIBLE_ABILITY`权限 | ||
| 125 | 117 | ||
| 126 | **需要权限**:ohos.permission.START_ABILITIES_FROM_BACKGROUND | 118 | **需要权限**:ohos.permission.START_ABILITIES_FROM_BACKGROUND |
| 127 | 119 | ||
| @@ -133,7 +125,7 @@ startAbility(want: Want): Promise<void> | |||
| 133 | 125 | ||
| 134 | | 参数名 | 类型 | 必填 | 说明 | | 126 | | 参数名 | 类型 | 必填 | 说明 | |
| 135 | | ------ | ----------------------------------- | ---- | ----------------------- | | 127 | | ------ | ----------------------------------- | ---- | ----------------------- | |
| 136 | -| want | [Want](../apis-ability-kit/js-apis-wantAgent.md) | 是 | 启动Ability的want信息。 | | 128 | +| want | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | 是 | 启动Ability的want信息。 | |
| 137 | 129 | ||
| 138 | **返回值:** | 130 | **返回值:** |
| 139 | 131 | ||
| @@ -171,8 +163,8 @@ startAbility(want: Want): Promise<void> | |||
| 171 | import { Want } from '@kit.AbilityKit'; | 163 | import { Want } from '@kit.AbilityKit'; |
| 172 | 164 | ||
| 173 | let want: Want = { | 165 | let want: Want = { |
| 174 | - bundleName: "com.example.myapp", | 166 | + bundleName: 'com.example.myapp', |
| 175 | - abilityName: "MyAbility" | 167 | + abilityName: 'MyAbility' |
| 176 | }; | 168 | }; |
| 177 | 169 | ||
| 178 | class MyStaticSubscriberExtensionAbility extends StaticSubscriberExtensionAbility { | 170 | class MyStaticSubscriberExtensionAbility extends StaticSubscriberExtensionAbility { |
| @@ -186,7 +178,7 @@ startAbility(want: Want): Promise<void> | |||
| 186 | }) | 178 | }) |
| 187 | .catch((error: BusinessError) => { | 179 | .catch((error: BusinessError) => { |
| 188 | // 处理业务逻辑错误 | 180 | // 处理业务逻辑错误 |
| 189 | - console.error(`startAbility failed, error.code: ${JSON.stringify(error.code)}, error.message: ${JSON.stringify(error.message)}.`); | 181 | + console.error(`startAbility failed, error.code: ${error.code}, error.message: ${error.message}.`); |
| 190 | }); | 182 | }); |
| 191 | } catch (paramError) { | 183 | } catch (paramError) { |
| 192 | // 处理入参错误异常 | 184 | // 处理入参错误异常 |
| @@ -196,4 +188,4 @@ startAbility(want: Want): Promise<void> | |||
| 196 | } | 188 | } |
| 197 | } | 189 | } |
| 198 | } | 190 | } |
| 199 | - ``` | 191 | + ``` |
| @@ -6,7 +6,13 @@ | |||
| 6 | <!--Tester: @wanghong1997--> | 6 | <!--Tester: @wanghong1997--> |
| 7 | <!--Adviser: @fang-jinxu--> | 7 | <!--Adviser: @fang-jinxu--> |
| 8 | 8 | ||
| 9 | -StaticSubscriberExtensionAbility模块提供静态订阅者ExtensionAbility类别的能力。 | 9 | +本模块是 BasicServicesKit 提供的静态订阅扩展能力基类,用于实现静态公共事件订阅。静态订阅是一种无需应用常驻运行即可接收公共事件的订阅方式。该能力适用于系统服务或系统应用需要在特定公共事件发生时执行后台处理的场景。 |
| 10 | + | ||
| 11 | +`StaticSubscriberExtensionAbility`基类提供两个关键成员:`onReceiveEvent`方法与`context`属性。`context`属性类型为 [StaticSubscriberExtensionContext](./js-apis-application-StaticSubscriberExtensionContext-sys.md),是扩展能力的运行上下文,继承自`ExtensionContext`,提供`startAbility`方法用于在事件处理过程中拉起同应用内的其他 Ability。 | ||
| 12 | + | ||
| 13 | +**API 组合使用关系说明:** | ||
| 14 | + | ||
| 15 | +本模块典型使用流程为"继承基类 → 重写`onReceiveEvent` → 系统拉起回调 → 读取事件数据 → 拉起目标 Ability"。需注意,`context.startAbility`仅能拉起与当前`StaticSubscriberExtensionAbility`属于同一应用的 Ability。 | ||
| 10 | 16 | ||
| 11 | > **说明:** | 17 | > **说明:** |
| 12 | > | 18 | > |
| @@ -30,13 +36,15 @@ import { StaticSubscriberExtensionAbility } from '@kit.BasicServicesKit'; | |||
| 30 | 36 | ||
| 31 | | 名称 | 类型 | 只读 | 可选 | 说明 | | 37 | | 名称 | 类型 | 只读 | 可选 | 说明 | |
| 32 | | ------- | ------------------------------------------------------------ | ---- | ---- | -------- | | 38 | | ------- | ------------------------------------------------------------ | ---- | ---- | -------- | |
| 33 | -| context<sup>10+</sup> | [StaticSubscriberExtensionContext](js-apis-application-StaticSubscriberExtensionContext-sys.md) | 否 | 否 | 上下文。 | | 39 | +| context<sup>10+</sup> | [StaticSubscriberExtensionContext](js-apis-application-StaticSubscriberExtensionContext-sys.md) | 否 | 否 | 静态订阅ExtensionAbility的上下文。 | |
| 34 | 40 | ||
| 35 | ## StaticSubscriberExtensionAbility.onReceiveEvent | 41 | ## StaticSubscriberExtensionAbility.onReceiveEvent |
| 36 | 42 | ||
| 37 | onReceiveEvent(event: CommonEventData): void | 43 | onReceiveEvent(event: CommonEventData): void |
| 38 | 44 | ||
| 39 | -静态订阅者通用事件回调。 | 45 | +静态订阅公共事件的回调函数。 |
| 46 | + | ||
| 47 | +**模型约束:** 此接口仅可在Stage模型下使用。 | ||
| 40 | 48 | ||
| 41 | **系统能力**:SystemCapability.Ability.AbilityRuntime.Core | 49 | **系统能力**:SystemCapability.Ability.AbilityRuntime.Core |
| 42 | 50 | ||
| @@ -46,15 +54,15 @@ onReceiveEvent(event: CommonEventData): void | |||
| 46 | 54 | ||
| 47 | | 参数名 | 类型 | 必填 | 说明 | | 55 | | 参数名 | 类型 | 必填 | 说明 | |
| 48 | | -------- | -------- | -------- | -------- | | 56 | | -------- | -------- | -------- | -------- | |
| 49 | -| event | [CommonEventData](./js-apis-inner-commonEvent-commonEventData.md) | 是 | 静态订阅者通用事件回调。 | | 57 | +| event | [CommonEventData](./js-apis-inner-commonEvent-commonEventData.md) | 是 | 静态订阅接收到的公共事件数据。 | |
| 50 | 58 | ||
| 51 | **示例:** | 59 | **示例:** |
| 52 | ```ts | 60 | ```ts |
| 53 | import { commonEventManager } from '@kit.BasicServicesKit'; | 61 | import { commonEventManager } from '@kit.BasicServicesKit'; |
| 54 | 62 | ||
| 55 | - class MyStaticSubscriberExtensionAbility extends StaticSubscriberExtensionAbility { | 63 | + class MyStaticSubscriberExtensionAbility extends StaticSubscriberExtensionAbility { |
| 56 | - onReceiveEvent(event: commonEventManager.CommonEventData) { | 64 | + onReceiveEvent(event: commonEventManager.CommonEventData) { |
| 57 | - console.info(`onReceiveEvent, event: ${JSON.stringify(event)}`); | 65 | + console.info(`onReceiveEvent, event: ${JSON.stringify(event)}`); |
| 58 | - } | ||
| 59 | } | 66 | } |
| 60 | - ``` | 67 | + } |
| 68 | + ``` | ||
| @@ -6,13 +6,13 @@ | |||
| 6 | <!--Tester: @wanghong1997--> | 6 | <!--Tester: @wanghong1997--> |
| 7 | <!--Adviser: @fang-jinxu--> | 7 | <!--Adviser: @fang-jinxu--> |
| 8 | 8 | ||
| 9 | -本模块提供了公共事件的能力,包括公共事件的权限列表,发布公共事件,订阅或取消订阅公共事件,获取或修改公共事件结果代码、结果数据等。 | 9 | +本模块提供了公共事件的能力,包括公共事件的权限列表,发布公共事件,订阅或取消订阅公共事件,获取或修改公共事件结果代码、结果数据等,适用于系统服务或应用间通过公共事件进行通信通知的场景,能够帮助开发者实现跨应用的事件发布与订阅,提升应用间的协同效率。 |
| 10 | 10 | ||
| 11 | > **说明:** | 11 | > **说明:** |
| 12 | > | 12 | > |
| 13 | > 从API version 7 开始支持,从API version 9 开始废弃,建议使用[@ohos.commonEventManager](js-apis-commonEventManager.md)替代。 | 13 | > 从API version 7 开始支持,从API version 9 开始废弃,建议使用[@ohos.commonEventManager](js-apis-commonEventManager.md)替代。 |
| 14 | > | 14 | > |
| 15 | -> 当前界面仅包含本模块的系统接口,其他公开接口参见[CommonEvent](./js-apis-commonEvent.md)。 | 15 | +> 当前页面仅包含本模块的系统接口,其他公开接口参见[CommonEvent](./js-apis-commonEvent.md)。 |
| 16 | 16 | ||
| 17 | ## 导入模块 | 17 | ## 导入模块 |
| 18 | 18 | ||
| @@ -22,7 +22,7 @@ import commonEvent from '@ohos.commonEvent'; | |||
| 22 | 22 | ||
| 23 | ## Support | 23 | ## Support |
| 24 | 24 | ||
| 25 | -系统公共事件是指由系统服务或系统应用发布的事件,订阅这些系统公共事件需要特定的权限。发布或订阅这些事件需要使用如下链接中的枚举定义。 | 25 | +系统公共事件是指由系统服务或系统应用发布的事件,订阅这些系统公共事件需要相应的权限。发布或订阅这些事件需要使用如下链接中的枚举定义。 |
| 26 | 26 | ||
| 27 | 全部系统公共事件枚举定义请参见[系统公共事件定义](./common_event/commonEvent-definitions.md)。 | 27 | 全部系统公共事件枚举定义请参见[系统公共事件定义](./common_event/commonEvent-definitions.md)。 |
| 28 | 28 | ||
| @@ -44,9 +44,9 @@ publishAsUser(event: string, userId: number, callback: AsyncCallback\<void>): vo | |||
| 44 | 44 | ||
| 45 | | 参数名 | 类型 | 必填 | 说明 | | 45 | | 参数名 | 类型 | 必填 | 说明 | |
| 46 | | -------- | -------------------- | ---- | ---------------------------------- | | 46 | | -------- | -------------------- | ---- | ---------------------------------- | |
| 47 | -| event | string | 是 | 表示要发送的公共事件。 | | 47 | +| event | string | 是 | 表示要发布的公共事件。 | |
| 48 | -| userId | number | 是 | 表示指定向该用户ID发送此公共事件。 | | 48 | +| userId | number | 是 | 表示指定向该用户ID发布此公共事件。 | |
| 49 | -| callback | AsyncCallback\<void> | 是 | 表示被指定的回调方法。 | | 49 | +| callback | AsyncCallback\<void> | 是 | 公共事件发布结果的回调方法。 | |
| 50 | 50 | ||
| 51 | **示例:** | 51 | **示例:** |
| 52 | 52 | ||
| @@ -54,19 +54,19 @@ publishAsUser(event: string, userId: number, callback: AsyncCallback\<void>): vo | |||
| 54 | import Base from '@ohos.base'; | 54 | import Base from '@ohos.base'; |
| 55 | 55 | ||
| 56 | // 发布公共事件回调 | 56 | // 发布公共事件回调 |
| 57 | -function publishCB(err:Base.BusinessError) { | 57 | +let publishCallBack = (err:Base.BusinessError) => { |
| 58 | if (err.code) { | 58 | if (err.code) { |
| 59 | - console.error(`publishAsUser failed, code is ${err.code}`); | 59 | + console.error(`Failed to publishAsUser. Code: ${err.code}, message: ${err.message}`); |
| 60 | } else { | 60 | } else { |
| 61 | - console.info("publishAsUser"); | 61 | + console.info('publishAsUser'); |
| 62 | } | 62 | } |
| 63 | } | 63 | } |
| 64 | 64 | ||
| 65 | // 指定发送的用户 | 65 | // 指定发送的用户 |
| 66 | -let userId = 100; | 66 | +const userId = 100; |
| 67 | 67 | ||
| 68 | // 发布公共事件 | 68 | // 发布公共事件 |
| 69 | -commonEvent.publishAsUser("event", userId, publishCB); | 69 | +commonEvent.publishAsUser('event', userId, publishCallBack); |
| 70 | ``` | 70 | ``` |
| 71 | 71 | ||
| 72 | ## commonEvent.publishAsUser<sup>(deprecated)</sup> | 72 | ## commonEvent.publishAsUser<sup>(deprecated)</sup> |
| @@ -76,6 +76,7 @@ publishAsUser(event: string, userId: number, options: CommonEventPublishData, ca | |||
| 76 | 以回调形式向指定用户发布公共事件并指定发布信息。 | 76 | 以回调形式向指定用户发布公共事件并指定发布信息。 |
| 77 | 77 | ||
| 78 | > **说明:** | 78 | > **说明:** |
| 79 | +> | ||
| 79 | > 从API version 8 开始支持,从API version 9 开始废弃,建议使用[commonEventManager.publishAsUser](js-apis-commonEventManager-sys.md#commoneventmanagerpublishasuser-1)替代。 | 80 | > 从API version 8 开始支持,从API version 9 开始废弃,建议使用[commonEventManager.publishAsUser](js-apis-commonEventManager-sys.md#commoneventmanagerpublishasuser-1)替代。 |
| 80 | 81 | ||
| 81 | **系统能力:** `SystemCapability.Notification.CommonEvent` | 82 | **系统能力:** `SystemCapability.Notification.CommonEvent` |
| @@ -87,9 +88,9 @@ publishAsUser(event: string, userId: number, options: CommonEventPublishData, ca | |||
| 87 | | 参数名 | 类型 | 必填 | 说明 | | 88 | | 参数名 | 类型 | 必填 | 说明 | |
| 88 | | -------- | ---------------------- | ---- | ---------------------- | | 89 | | -------- | ---------------------- | ---- | ---------------------- | |
| 89 | | event | string | 是 | 表示要发布的公共事件。 | | 90 | | event | string | 是 | 表示要发布的公共事件。 | |
| 90 | -| userId | number | 是 | 表示指定向该用户ID发送此公共事件。 | | 91 | +| userId | number | 是 | 表示指定向该用户ID发布此公共事件。 | |
| 91 | | options | [CommonEventPublishData](./js-apis-inner-commonEvent-commonEventPublishData.md) | 是 | 表示发布公共事件的属性。 | | 92 | | options | [CommonEventPublishData](./js-apis-inner-commonEvent-commonEventPublishData.md) | 是 | 表示发布公共事件的属性。 | |
| 92 | -| callback | AsyncCallback\<void> | 是 | 表示被指定的回调方法。 | | 93 | +| callback | AsyncCallback\<void> | 是 | 公共事件发布结果的回调方法。 | |
| 93 | 94 | ||
| 94 | **示例:** | 95 | **示例:** |
| 95 | 96 | ||
| @@ -100,16 +101,16 @@ import CommonEventManager from '@ohos.commonEventManager'; | |||
| 100 | 101 | ||
| 101 | // 公共事件相关信息 | 102 | // 公共事件相关信息 |
| 102 | let options:CommonEventManager.CommonEventPublishData = { | 103 | let options:CommonEventManager.CommonEventPublishData = { |
| 103 | - code: 0, // 公共事件的初始代码 | 104 | + code: 0, // 公共事件的初始代码 |
| 104 | - data: "initial data",// 公共事件的初始数据 | 105 | + data: 'initial data', // 公共事件的初始数据 |
| 105 | -} | 106 | +}; |
| 106 | 107 | ||
| 107 | // 发布公共事件回调 | 108 | // 发布公共事件回调 |
| 108 | -function publishCB(err:Base.BusinessError) { | 109 | +let publishCallBack = (err:Base.BusinessError) => { |
| 109 | if (err.code) { | 110 | if (err.code) { |
| 110 | - console.error(`publishAsUser failed, code is ${err.code}`); | 111 | + console.error(`Failed to publishAsUser. Code: ${err.code}, message: ${err.message}`); |
| 111 | } else { | 112 | } else { |
| 112 | - console.info("publishAsUser"); | 113 | + console.info('publishAsUser'); |
| 113 | } | 114 | } |
| 114 | } | 115 | } |
| 115 | 116 | ||
| @@ -117,5 +118,5 @@ function publishCB(err:Base.BusinessError) { | |||
| 117 | let userId = 100; | 118 | let userId = 100; |
| 118 | 119 | ||
| 119 | // 发布公共事件 | 120 | // 发布公共事件 |
| 120 | -commonEvent.publishAsUser("event", userId, options, publishCB); | 121 | +commonEvent.publishAsUser('event', userId, options, publishCallBack); |
| 121 | -``` | 122 | +``` |
| @@ -28,7 +28,7 @@ import commonEvent from '@ohos.commonEvent'; | |||
| 28 | 28 | ||
| 29 | publish(event: string, callback: AsyncCallback\<void>): void | 29 | publish(event: string, callback: AsyncCallback\<void>): void |
| 30 | 30 | ||
| 31 | -发布公共事件(回调形式)。 | 31 | +以回调形式发布公共事件。 |
| 32 | 32 | ||
| 33 | > **说明:** | 33 | > **说明:** |
| 34 | > 从API version 7 开始支持,从API version 9 开始废弃,建议使用[commonEventManager.publish](js-apis-commonEventManager.md#commoneventmanagerpublish)替代。 | 34 | > 从API version 7 开始支持,从API version 9 开始废弃,建议使用[commonEventManager.publish](js-apis-commonEventManager.md#commoneventmanagerpublish)替代。 |
| @@ -39,8 +39,8 @@ publish(event: string, callback: AsyncCallback\<void>): void | |||
| 39 | 39 | ||
| 40 | | 参数名 | 类型 | 必填 | 说明 | | 40 | | 参数名 | 类型 | 必填 | 说明 | |
| 41 | | -------- | -------------------- | ---- | ---------------------- | | 41 | | -------- | -------------------- | ---- | ---------------------- | |
| 42 | -| event | string | 是 | 表示要发送的公共事件。 | | 42 | +| event | string | 是 | 表示要发布的公共事件。 | |
| 43 | -| callback | AsyncCallback\<void> | 是 | 表示指定的回调方法。 | | 43 | +| callback | AsyncCallback\<void> | 是 | 表示发布公共事件的回调方法。 | |
| 44 | 44 | ||
| 45 | **示例:** | 45 | **示例:** |
| 46 | 46 | ||
| @@ -48,23 +48,23 @@ publish(event: string, callback: AsyncCallback\<void>): void | |||
| 48 | import Base from '@ohos.base'; | 48 | import Base from '@ohos.base'; |
| 49 | 49 | ||
| 50 | // 发布公共事件回调 | 50 | // 发布公共事件回调 |
| 51 | -function publishCB(err:Base.BusinessError) { | 51 | +let publishCallBack = (err: Base.BusinessError) => { |
| 52 | if (err.code) { | 52 | if (err.code) { |
| 53 | - console.error(`publish failed, code is ${err.code}`); | 53 | + console.error(`publish failed, code is ${err.code}, message is ${err.message}`); |
| 54 | } else { | 54 | } else { |
| 55 | - console.info("publish"); | 55 | + console.info('publish'); |
| 56 | } | 56 | } |
| 57 | } | 57 | } |
| 58 | 58 | ||
| 59 | // 发布公共事件 | 59 | // 发布公共事件 |
| 60 | -commonEvent.publish("event", publishCB); | 60 | +commonEvent.publish("event", publishCallBack); |
| 61 | ``` | 61 | ``` |
| 62 | 62 | ||
| 63 | ## commonEvent.publish<sup>(deprecated)</sup> | 63 | ## commonEvent.publish<sup>(deprecated)</sup> |
| 64 | 64 | ||
| 65 | publish(event: string, options: CommonEventPublishData, callback: AsyncCallback\<void>): void | 65 | publish(event: string, options: CommonEventPublishData, callback: AsyncCallback\<void>): void |
| 66 | 66 | ||
| 67 | -以回调的形式发布公共事件。 | 67 | +以回调形式发布公共事件。 |
| 68 | 68 | ||
| 69 | > **说明:** | 69 | > **说明:** |
| 70 | > 从API version 7 开始支持,从API version 9 开始废弃,建议使用[commonEventManager.publish](js-apis-commonEventManager.md#commoneventmanagerpublish-1)替代。 | 70 | > 从API version 7 开始支持,从API version 9 开始废弃,建议使用[commonEventManager.publish](js-apis-commonEventManager.md#commoneventmanagerpublish-1)替代。 |
| @@ -77,7 +77,7 @@ publish(event: string, options: CommonEventPublishData, callback: AsyncCallback\ | |||
| 77 | | -------- | ---------------------- | ---- | ---------------------- | | 77 | | -------- | ---------------------- | ---- | ---------------------- | |
| 78 | | event | string | 是 | 表示要发布的公共事件。 | | 78 | | event | string | 是 | 表示要发布的公共事件。 | |
| 79 | | options | [CommonEventPublishData](./js-apis-inner-commonEvent-commonEventPublishData.md) | 是 | 表示发布公共事件的属性。 | | 79 | | options | [CommonEventPublishData](./js-apis-inner-commonEvent-commonEventPublishData.md) | 是 | 表示发布公共事件的属性。 | |
| 80 | -| callback | AsyncCallback\<void> | 是 | 表示指定的回调方法。 | | 80 | +| callback | AsyncCallback\<void> | 是 | 表示发布公共事件的回调方法。 | |
| 81 | 81 | ||
| 82 | **示例:** | 82 | **示例:** |
| 83 | 83 | ||
| @@ -91,19 +91,19 @@ let options:CommonEventManager.CommonEventPublishData = { | |||
| 91 | code: 0, // 公共事件的初始代码 | 91 | code: 0, // 公共事件的初始代码 |
| 92 | data: "initial data", // 公共事件的初始数据 | 92 | data: "initial data", // 公共事件的初始数据 |
| 93 | isOrdered: true // 有序公共事件 | 93 | isOrdered: true // 有序公共事件 |
| 94 | -} | 94 | +}; |
| 95 | 95 | ||
| 96 | // 发布公共事件回调 | 96 | // 发布公共事件回调 |
| 97 | -function publishCB(err:Base.BusinessError) { | 97 | +let publishCallBack = (err: Base.BusinessError) => { |
| 98 | if (err.code) { | 98 | if (err.code) { |
| 99 | - console.error(`publish failed, code is ${err.code}`); | 99 | + console.error(`publish failed, code is ${err.code}, message is ${err.message}`); |
| 100 | } else { | 100 | } else { |
| 101 | console.info("publish"); | 101 | console.info("publish"); |
| 102 | } | 102 | } |
| 103 | } | 103 | } |
| 104 | 104 | ||
| 105 | // 发布公共事件 | 105 | // 发布公共事件 |
| 106 | -commonEvent.publish("event", options, publishCB); | 106 | +commonEvent.publish("event", options, publishCallBack); |
| 107 | ``` | 107 | ``` |
| 108 | 108 | ||
| 109 | ## commonEvent.createSubscriber<sup>(deprecated)</sup> | 109 | ## commonEvent.createSubscriber<sup>(deprecated)</sup> |
| @@ -131,7 +131,7 @@ createSubscriber(subscribeInfo: CommonEventSubscribeInfo, callback: AsyncCallbac | |||
| 131 | import Base from '@ohos.base'; | 131 | import Base from '@ohos.base'; |
| 132 | import CommonEventManager from '@ohos.commonEventManager'; | 132 | import CommonEventManager from '@ohos.commonEventManager'; |
| 133 | 133 | ||
| 134 | -let subscriber:CommonEventManager.CommonEventSubscriber; // 用于保存创建成功的订阅者对象,后续使用其完成订阅及退订的动作 | 134 | +let subscriber:CommonEventManager.CommonEventSubscriber; // 用于保存创建成功的订阅者对象,后续使用其完成订阅及取消订阅的动作 |
| 135 | 135 | ||
| 136 | // 订阅者信息 | 136 | // 订阅者信息 |
| 137 | let subscribeInfo:CommonEventManager.CommonEventSubscribeInfo = { | 137 | let subscribeInfo:CommonEventManager.CommonEventSubscribeInfo = { |
| @@ -139,9 +139,9 @@ let subscribeInfo:CommonEventManager.CommonEventSubscribeInfo = { | |||
| 139 | }; | 139 | }; |
| 140 | 140 | ||
| 141 | // 创建订阅者回调 | 141 | // 创建订阅者回调 |
| 142 | -function createCB(err:Base.BusinessError, commonEventSubscriber:CommonEventManager.CommonEventSubscriber) { | 142 | +let createCallBack = (err:Base.BusinessError, commonEventSubscriber:CommonEventManager.CommonEventSubscriber) => { |
| 143 | if (err.code) { | 143 | if (err.code) { |
| 144 | - console.error(`createSubscriber failed, code is ${err.code}`); | 144 | + console.error(`createSubscriber failed, code is ${err.code}, message is ${err.message}`); |
| 145 | } else { | 145 | } else { |
| 146 | console.info("createSubscriber"); | 146 | console.info("createSubscriber"); |
| 147 | subscriber = commonEventSubscriber; | 147 | subscriber = commonEventSubscriber; |
| @@ -149,7 +149,7 @@ function createCB(err:Base.BusinessError, commonEventSubscriber:CommonEventManag | |||
| 149 | } | 149 | } |
| 150 | 150 | ||
| 151 | // 创建订阅者 | 151 | // 创建订阅者 |
| 152 | -commonEvent.createSubscriber(subscribeInfo, createCB); | 152 | +commonEvent.createSubscriber(subscribeInfo, createCallBack); |
| 153 | ``` | 153 | ``` |
| 154 | 154 | ||
| 155 | ## commonEvent.createSubscriber<sup>(deprecated)</sup> | 155 | ## commonEvent.createSubscriber<sup>(deprecated)</sup> |
| @@ -180,7 +180,7 @@ createSubscriber(subscribeInfo: CommonEventSubscribeInfo): Promise\<CommonEventS | |||
| 180 | import Base from '@ohos.base'; | 180 | import Base from '@ohos.base'; |
| 181 | import CommonEventManager from '@ohos.commonEventManager'; | 181 | import CommonEventManager from '@ohos.commonEventManager'; |
| 182 | 182 | ||
| 183 | -let subscriber:CommonEventManager.CommonEventSubscriber; // 用于保存创建成功的订阅者对象,后续使用其完成订阅及退订的动作 | 183 | +let subscriber:CommonEventManager.CommonEventSubscriber; // 用于保存创建成功的订阅者对象,后续使用其完成订阅及取消订阅的动作 |
| 184 | 184 | ||
| 185 | // 订阅者信息 | 185 | // 订阅者信息 |
| 186 | let subscribeInfo:CommonEventManager.CommonEventSubscribeInfo = { | 186 | let subscribeInfo:CommonEventManager.CommonEventSubscribeInfo = { |
| @@ -192,7 +192,7 @@ commonEvent.createSubscriber(subscribeInfo).then((commonEventSubscriber:CommonEv | |||
| 192 | console.info("createSubscriber"); | 192 | console.info("createSubscriber"); |
| 193 | subscriber = commonEventSubscriber; | 193 | subscriber = commonEventSubscriber; |
| 194 | }).catch((err:Base.BusinessError) => { | 194 | }).catch((err:Base.BusinessError) => { |
| 195 | - console.error(`createSubscriber failed, code is ${err.code}`); | 195 | + console.error(`createSubscriber failed, code is ${err.code}, message is ${err.message}`); |
| 196 | }); | 196 | }); |
| 197 | ``` | 197 | ``` |
| 198 | 198 | ||
| @@ -212,7 +212,7 @@ subscribe(subscriber: CommonEventSubscriber, callback: AsyncCallback\<CommonEven | |||
| 212 | | 参数名 | 类型 | 必填 | 说明 | | 212 | | 参数名 | 类型 | 必填 | 说明 | |
| 213 | | ---------- | ---------------------------------------------------- | ---- | -------------------------------- | | 213 | | ---------- | ---------------------------------------------------- | ---- | -------------------------------- | |
| 214 | | subscriber | [CommonEventSubscriber](./js-apis-inner-commonEvent-commonEventSubscriber.md) | 是 | 表示订阅者对象。 | | 214 | | subscriber | [CommonEventSubscriber](./js-apis-inner-commonEvent-commonEventSubscriber.md) | 是 | 表示订阅者对象。 | |
| 215 | -| callback | AsyncCallback\<[CommonEventData](./js-apis-inner-commonEvent-commonEventData.md)> | 是 | 表示接收公共事件数据的回调函数。 | | 215 | +| callback | AsyncCallback\<[CommonEventData](./js-apis-inner-commonEvent-commonEventData.md)> | 是 | 表示接收公共事件数据的回调方法。 | |
| 216 | 216 | ||
| 217 | **示例:** | 217 | **示例:** |
| 218 | 218 | ||
| @@ -220,7 +220,7 @@ subscribe(subscriber: CommonEventSubscriber, callback: AsyncCallback\<CommonEven | |||
| 220 | import Base from '@ohos.base'; | 220 | import Base from '@ohos.base'; |
| 221 | import CommonEventManager from '@ohos.commonEventManager'; | 221 | import CommonEventManager from '@ohos.commonEventManager'; |
| 222 | 222 | ||
| 223 | -let subscriber:CommonEventManager.CommonEventSubscriber;// 用于保存创建成功的订阅者对象,后续使用其完成订阅及退订的动作 | 223 | +let subscriber:CommonEventManager.CommonEventSubscriber; // 用于保存创建成功的订阅者对象,后续使用其完成订阅及取消订阅的动作 |
| 224 | 224 | ||
| 225 | // 订阅者信息 | 225 | // 订阅者信息 |
| 226 | let subscribeInfo:CommonEventManager.CommonEventSubscribeInfo = { | 226 | let subscribeInfo:CommonEventManager.CommonEventSubscribeInfo = { |
| @@ -228,28 +228,28 @@ let subscribeInfo:CommonEventManager.CommonEventSubscribeInfo = { | |||
| 228 | }; | 228 | }; |
| 229 | 229 | ||
| 230 | // 订阅公共事件回调 | 230 | // 订阅公共事件回调 |
| 231 | -function subscribeCB(err:Base.BusinessError, data:CommonEventManager.CommonEventData) { | 231 | +let subscribeCallBack = (err:Base.BusinessError, data:CommonEventManager.CommonEventData) => { |
| 232 | if (err.code) { | 232 | if (err.code) { |
| 233 | - console.error(`subscribe failed, code is ${err.code}`); | 233 | + console.error(`subscribe failed, code is ${err.code}, message is ${err.message}`); |
| 234 | } else { | 234 | } else { |
| 235 | console.info("subscribe " + JSON.stringify(data)); | 235 | console.info("subscribe " + JSON.stringify(data)); |
| 236 | } | 236 | } |
| 237 | } | 237 | } |
| 238 | 238 | ||
| 239 | // 创建订阅者回调 | 239 | // 创建订阅者回调 |
| 240 | -function createCB(err:Base.BusinessError, commonEventSubscriber:CommonEventManager.CommonEventSubscriber) { | 240 | +let createCallBack = (err:Base.BusinessError, commonEventSubscriber:CommonEventManager.CommonEventSubscriber) => { |
| 241 | if (err.code) { | 241 | if (err.code) { |
| 242 | - console.error(`createSubscriber failed, code is ${err.code}`); | 242 | + console.error(`createSubscriber failed, code is ${err.code}, message is ${err.message}`); |
| 243 | } else { | 243 | } else { |
| 244 | console.info("createSubscriber"); | 244 | console.info("createSubscriber"); |
| 245 | subscriber = commonEventSubscriber; | 245 | subscriber = commonEventSubscriber; |
| 246 | - // Subscribe to a common event. | 246 | + // 订阅公共事件 |
| 247 | - commonEvent.subscribe(subscriber, subscribeCB); | 247 | + commonEvent.subscribe(subscriber, subscribeCallBack); |
| 248 | } | 248 | } |
| 249 | } | 249 | } |
| 250 | 250 | ||
| 251 | // 创建订阅者 | 251 | // 创建订阅者 |
| 252 | -commonEvent.createSubscriber(subscribeInfo, createCB); | 252 | +commonEvent.createSubscriber(subscribeInfo, createCallBack); |
| 253 | ``` | 253 | ``` |
| 254 | 254 | ||
| 255 | ## commonEvent.unsubscribe<sup>(deprecated)</sup> | 255 | ## commonEvent.unsubscribe<sup>(deprecated)</sup> |
| @@ -276,7 +276,7 @@ unsubscribe(subscriber: CommonEventSubscriber, callback?: AsyncCallback\<void>): | |||
| 276 | import Base from '@ohos.base'; | 276 | import Base from '@ohos.base'; |
| 277 | import CommonEventManager from '@ohos.commonEventManager'; | 277 | import CommonEventManager from '@ohos.commonEventManager'; |
| 278 | 278 | ||
| 279 | -let subscriber:CommonEventManager.CommonEventSubscriber; // 用于保存创建成功的订阅者对象,后续使用其完成订阅及退订的动作 | 279 | +let subscriber:CommonEventManager.CommonEventSubscriber; // 用于保存创建成功的订阅者对象,后续使用其完成订阅及取消订阅的动作 |
| 280 | 280 | ||
| 281 | // 订阅者信息 | 281 | // 订阅者信息 |
| 282 | let subscribeInfo:CommonEventManager.CommonEventSubscribeInfo = { | 282 | let subscribeInfo:CommonEventManager.CommonEventSubscribeInfo = { |
| @@ -284,38 +284,39 @@ let subscribeInfo:CommonEventManager.CommonEventSubscribeInfo = { | |||
| 284 | }; | 284 | }; |
| 285 | 285 | ||
| 286 | // 订阅公共事件回调 | 286 | // 订阅公共事件回调 |
| 287 | -function subscribeCB(err:Base.BusinessError, data:CommonEventManager.CommonEventData) { | 287 | +let subscribeCallBack = (err:Base.BusinessError, data:CommonEventManager.CommonEventData) => { |
| 288 | if (err.code) { | 288 | if (err.code) { |
| 289 | - console.error(`subscribe failed, code is ${err.code}`); | 289 | + console.error(`subscribe failed, code is ${err.code}, message is ${err.message}`); |
| 290 | } else { | 290 | } else { |
| 291 | console.info("subscribe " + JSON.stringify(data)); | 291 | console.info("subscribe " + JSON.stringify(data)); |
| 292 | } | 292 | } |
| 293 | } | 293 | } |
| 294 | 294 | ||
| 295 | // 创建订阅者回调 | 295 | // 创建订阅者回调 |
| 296 | -function createCB(err:Base.BusinessError, commonEventSubscriber:CommonEventManager.CommonEventSubscriber) { | 296 | +let createCallBack = (err:Base.BusinessError, commonEventSubscriber:CommonEventManager.CommonEventSubscriber) => { |
| 297 | if (err.code) { | 297 | if (err.code) { |
| 298 | - console.error(`createSubscriber failed, code is ${err.code}`); | 298 | + console.error(`createSubscriber failed, code is ${err.code}, message is ${err.message}`); |
| 299 | } else { | 299 | } else { |
| 300 | console.info("createSubscriber"); | 300 | console.info("createSubscriber"); |
| 301 | subscriber = commonEventSubscriber; | 301 | subscriber = commonEventSubscriber; |
| 302 | - // Subscribe to a common event. | 302 | + // 订阅公共事件 |
| 303 | - commonEvent.subscribe(subscriber, subscribeCB); | 303 | + commonEvent.subscribe(subscriber, subscribeCallBack); |
| 304 | } | 304 | } |
| 305 | } | 305 | } |
| 306 | 306 | ||
| 307 | // 取消订阅公共事件回调 | 307 | // 取消订阅公共事件回调 |
| 308 | -function unsubscribeCB(err:Base.BusinessError) { | 308 | +let unsubscribeCallback = (err: Base.BusinessError) => { |
| 309 | if (err.code) { | 309 | if (err.code) { |
| 310 | - console.error(`unsubscribe failed, code is ${err.code}`); | 310 | + console.error(`unsubscribe failed, code is ${err.code}, message is ${err.message}`); |
| 311 | } else { | 311 | } else { |
| 312 | console.info("unsubscribe"); | 312 | console.info("unsubscribe"); |
| 313 | } | 313 | } |
| 314 | } | 314 | } |
| 315 | 315 | ||
| 316 | // 创建订阅者 | 316 | // 创建订阅者 |
| 317 | -commonEvent.createSubscriber(subscribeInfo, createCB); | 317 | +commonEvent.createSubscriber(subscribeInfo, createCallBack); |
| 318 | 318 | ||
| 319 | // 取消订阅公共事件 | 319 | // 取消订阅公共事件 |
| 320 | -commonEvent.unsubscribe(subscriber, unsubscribeCB); | 320 | +// 注意:需在subscriber创建成功后(即createCallBack回调执行后)调用,此处仅展示API用法 |
| 321 | -``` | 321 | +commonEvent.unsubscribe(subscriber, unsubscribeCallback); |
| 322 | +``` | ||
| @@ -6,7 +6,7 @@ | |||
| 6 | <!--Tester: @wanghong1997--> | 6 | <!--Tester: @wanghong1997--> |
| 7 | <!--Adviser: @fang-jinxu--> | 7 | <!--Adviser: @fang-jinxu--> |
| 8 | 8 | ||
| 9 | -本模块提供了公共事件相关的能力,包括发布公共事件、订阅公共事件以及退订公共事件。 | 9 | +本模块提供了公共事件相关的系统接口能力,包括发布公共事件到指定用户、移除粘性公共事件以及设置静态订阅公共事件的使能状态。粘性公共事件是指发布后会被系统保留的公共事件,当新的订阅者注册后仍可接收到该事件;非粘性事件仅投递给发布时已注册的订阅者。 |
| 10 | 10 | ||
| 11 | > **说明:** | 11 | > **说明:** |
| 12 | > | 12 | > |
| @@ -26,7 +26,7 @@ import { commonEventManager } from '@kit.BasicServicesKit'; | |||
| 26 | 26 | ||
| 27 | 全部系统公共事件枚举定义请参见[系统定义的公共事件](./common_event/commonEventManager-definitions-sys.md)。 | 27 | 全部系统公共事件枚举定义请参见[系统定义的公共事件](./common_event/commonEventManager-definitions-sys.md)。 |
| 28 | 28 | ||
| 29 | -## commonEventManager.publishAsUser<sup> | 29 | +## commonEventManager.publishAsUser |
| 30 | 30 | ||
| 31 | publishAsUser(event: string, userId: number, callback: AsyncCallback\<void>): void | 31 | publishAsUser(event: string, userId: number, callback: AsyncCallback\<void>): void |
| 32 | 32 | ||
| @@ -40,8 +40,8 @@ publishAsUser(event: string, userId: number, callback: AsyncCallback\<void>): vo | |||
| 40 | 40 | ||
| 41 | | 参数名 | 类型 | 必填 | 说明 | | 41 | | 参数名 | 类型 | 必填 | 说明 | |
| 42 | | -------- | -------------------- | ---- | ---------------------------------- | | 42 | | -------- | -------------------- | ---- | ---------------------------------- | |
| 43 | -| event | string | 是 | 表示要发送的公共事件。详见[系统定义的公共事件](./common_event/commonEventManager-definitions-sys.md)。 | | 43 | +| event | string | 是 | 表示要发布的公共事件。详见[系统定义的公共事件](./common_event/commonEventManager-definitions-sys.md)。 | |
| 44 | -| userId | number | 是 | 表示指定向该用户ID发送此公共事件。 | | 44 | +| userId | number | 是 | 表示指定接收此公共事件的用户ID。 | |
| 45 | | callback | AsyncCallback\<void> | 是 | 回调函数。当公共事件发布成功,err为undefined,否则为错误对象。 | | 45 | | callback | AsyncCallback\<void> | 是 | 回调函数。当公共事件发布成功,err为undefined,否则为错误对象。 | |
| 46 | 46 | ||
| 47 | **错误码:** | 47 | **错误码:** |
| @@ -95,7 +95,7 @@ publishAsUser(event: string, userId: number, options: CommonEventPublishData, ca | |||
| 95 | | 参数名 | 类型 | 必填 | 说明 | | 95 | | 参数名 | 类型 | 必填 | 说明 | |
| 96 | | -------- | ---------------------- | ---- | ---------------------- | | 96 | | -------- | ---------------------- | ---- | ---------------------- | |
| 97 | | event | string | 是 | 表示要发布的公共事件。详见[系统定义的公共事件](./common_event/commonEventManager-definitions-sys.md)。 | | 97 | | event | string | 是 | 表示要发布的公共事件。详见[系统定义的公共事件](./common_event/commonEventManager-definitions-sys.md)。 | |
| 98 | -| userId | number | 是 | 表示指定向该用户ID发送此公共事件。 | | 98 | +| userId | number | 是 | 表示指定接收此公共事件的用户ID。 | |
| 99 | | options | [CommonEventPublishData](./js-apis-inner-commonEvent-commonEventPublishData.md) | 是 | 表示发布公共事件的属性。 | | 99 | | options | [CommonEventPublishData](./js-apis-inner-commonEvent-commonEventPublishData.md) | 是 | 表示发布公共事件的属性。 | |
| 100 | | callback | AsyncCallback\<void> | 是 | 回调函数。当公共事件发布成功,err为undefined,否则为错误对象。 | | 100 | | callback | AsyncCallback\<void> | 是 | 回调函数。当公共事件发布成功,err为undefined,否则为错误对象。 | |
| 101 | 101 | ||
| @@ -118,10 +118,10 @@ publishAsUser(event: string, userId: number, options: CommonEventPublishData, ca | |||
| 118 | import { BusinessError } from '@kit.BasicServicesKit'; | 118 | import { BusinessError } from '@kit.BasicServicesKit'; |
| 119 | 119 | ||
| 120 | // 公共事件相关信息 | 120 | // 公共事件相关信息 |
| 121 | -let options:commonEventManager.CommonEventPublishData = { | 121 | +let options: commonEventManager.CommonEventPublishData = { |
| 122 | code: 0, // 公共事件的初始代码 | 122 | code: 0, // 公共事件的初始代码 |
| 123 | - data: 'initial data',// 公共事件的初始数据 | 123 | + data: 'initial data', // 公共事件的初始数据 |
| 124 | -} | 124 | +}; |
| 125 | 125 | ||
| 126 | // 指定发送的用户 | 126 | // 指定发送的用户 |
| 127 | let userId = 100; | 127 | let userId = 100; |
| @@ -148,7 +148,7 @@ removeStickyCommonEvent(event: string, callback: AsyncCallback\<void>): void | |||
| 148 | 148 | ||
| 149 | **系统能力:** SystemCapability.Notification.CommonEvent | 149 | **系统能力:** SystemCapability.Notification.CommonEvent |
| 150 | 150 | ||
| 151 | -**需要权限**: ohos.permission.COMMONEVENT_STICKY | 151 | +**需要权限**:ohos.permission.COMMONEVENT_STICKY |
| 152 | 152 | ||
| 153 | **系统接口**:此接口为系统接口。 | 153 | **系统接口**:此接口为系统接口。 |
| 154 | 154 | ||
| @@ -157,7 +157,7 @@ removeStickyCommonEvent(event: string, callback: AsyncCallback\<void>): void | |||
| 157 | | 参数名 | 类型 | 必填 | 说明 | | 157 | | 参数名 | 类型 | 必填 | 说明 | |
| 158 | | -------- | -------------------- | ---- | -------------------------------- | | 158 | | -------- | -------------------- | ---- | -------------------------------- | |
| 159 | | event | string | 是 | 表示被移除的粘性公共事件。详见[系统定义的公共事件](./common_event/commonEventManager-definitions-sys.md)。 | | 159 | | event | string | 是 | 表示被移除的粘性公共事件。详见[系统定义的公共事件](./common_event/commonEventManager-definitions-sys.md)。 | |
| 160 | -| callback | AsyncCallback\<void> | 是 | 回调函数。当移除粘性事件成功,err为undefined,否则为错误对象。 | | 160 | +| callback | AsyncCallback\<void> | 是 | 回调函数。当移除粘性公共事件成功,err为undefined,否则为错误对象。 | |
| 161 | 161 | ||
| 162 | **错误码:** | 162 | **错误码:** |
| 163 | 163 | ||
| @@ -179,7 +179,7 @@ import { BusinessError } from '@kit.BasicServicesKit'; | |||
| 179 | 179 | ||
| 180 | commonEventManager.removeStickyCommonEvent('sticky_event', (err: BusinessError) => { | 180 | commonEventManager.removeStickyCommonEvent('sticky_event', (err: BusinessError) => { |
| 181 | if (err) { | 181 | if (err) { |
| 182 | - console.error(`removeStickyCommonEvent failed, errCode: ${err.code}, errMes: ${err.message}`); | 182 | + console.error(`removeStickyCommonEvent failed, errCode: ${err.code}, errMsg: ${err.message}`); |
| 183 | return; | 183 | return; |
| 184 | } | 184 | } |
| 185 | console.info(`removeStickyCommonEvent success`); | 185 | console.info(`removeStickyCommonEvent success`); |
| @@ -190,11 +190,11 @@ commonEventManager.removeStickyCommonEvent('sticky_event', (err: BusinessError) | |||
| 190 | 190 | ||
| 191 | removeStickyCommonEvent(event: string): Promise\<void> | 191 | removeStickyCommonEvent(event: string): Promise\<void> |
| 192 | 192 | ||
| 193 | -移除粘性公共事件。使用Promise异步回调。 | 193 | +移除已发布的粘性公共事件。使用Promise异步回调。 |
| 194 | 194 | ||
| 195 | **系统能力:** SystemCapability.Notification.CommonEvent | 195 | **系统能力:** SystemCapability.Notification.CommonEvent |
| 196 | 196 | ||
| 197 | -**需要权限**: ohos.permission.COMMONEVENT_STICKY | 197 | +**需要权限**:ohos.permission.COMMONEVENT_STICKY |
| 198 | 198 | ||
| 199 | **系统接口**:此接口为系统接口。 | 199 | **系统接口**:此接口为系统接口。 |
| 200 | 200 | ||
| @@ -202,7 +202,7 @@ removeStickyCommonEvent(event: string): Promise\<void> | |||
| 202 | 202 | ||
| 203 | | 参数名 | 类型 | 必填 | 说明 | | 203 | | 参数名 | 类型 | 必填 | 说明 | |
| 204 | | ------ | ------ | ---- | -------------------------- | | 204 | | ------ | ------ | ---- | -------------------------- | |
| 205 | -| event | string | 是 | 表示被移除的粘性公共事件。详见[系统定义的公共事件](./common_event/commonEventManager-definitions-sys.md)。 | | 205 | +| event | string | 是 | 表示被移除的粘性公共事件。详见[系统定义的公共事件](./common_event/commonEventManager-definitions.md)。 | |
| 206 | 206 | ||
| 207 | **返回值:** | 207 | **返回值:** |
| 208 | 208 | ||
| @@ -230,8 +230,8 @@ import { BusinessError } from '@kit.BasicServicesKit'; | |||
| 230 | 230 | ||
| 231 | commonEventManager.removeStickyCommonEvent('sticky_event').then(() => { | 231 | commonEventManager.removeStickyCommonEvent('sticky_event').then(() => { |
| 232 | console.info(`removeStickyCommonEvent success`); | 232 | console.info(`removeStickyCommonEvent success`); |
| 233 | -}).catch ((err: BusinessError) => { | 233 | +}).catch((err: BusinessError) => { |
| 234 | - console.error(`removeStickyCommonEvent failed, errCode: ${err.code}, errMes: ${err.message}`); | 234 | + console.error(`removeStickyCommonEvent failed, errCode: ${err.code}, errMsg: ${err.message}`); |
| 235 | }); | 235 | }); |
| 236 | ``` | 236 | ``` |
| 237 | 237 | ||
| @@ -251,7 +251,7 @@ setStaticSubscriberState(enable: boolean, callback: AsyncCallback\<void>): void | |||
| 251 | 251 | ||
| 252 | | 参数名 | 类型 | 必填 | 说明 | | 252 | | 参数名 | 类型 | 必填 | 说明 | |
| 253 | | ------ | ------ | ---- | -------------------------- | | 253 | | ------ | ------ | ---- | -------------------------- | |
| 254 | -| enable | boolean | 是 | 表示静态订阅事件使能状态。 true:使能 false:去使能。 | | 254 | +| enable | boolean | 是 | 表示静态订阅事件使能状态。true:使能,false:去使能。 | |
| 255 | | callback | AsyncCallback\<void> | 是 | 回调函数。当设置静态订阅事件使能状态成功,err为undefined,否则为错误对象。 | | 255 | | callback | AsyncCallback\<void> | 是 | 回调函数。当设置静态订阅事件使能状态成功,err为undefined,否则为错误对象。 | |
| 256 | 256 | ||
| 257 | **错误码:** | 257 | **错误码:** |
| @@ -272,7 +272,7 @@ import { BusinessError } from '@kit.BasicServicesKit'; | |||
| 272 | 272 | ||
| 273 | commonEventManager.setStaticSubscriberState(true, (err: BusinessError) => { | 273 | commonEventManager.setStaticSubscriberState(true, (err: BusinessError) => { |
| 274 | if (err.code != 0) { | 274 | if (err.code != 0) { |
| 275 | - console.error(`setStaticSubscriberState failed, errCode: ${err.code}, errMes: ${err.message}`); | 275 | + console.error(`setStaticSubscriberState failed, errCode: ${err.code}, errMsg: ${err.message}`); |
| 276 | return; | 276 | return; |
| 277 | } | 277 | } |
| 278 | console.info(`setStaticSubscriberState success`); | 278 | console.info(`setStaticSubscriberState success`); |
| @@ -295,7 +295,7 @@ setStaticSubscriberState(enable: boolean): Promise\<void> | |||
| 295 | 295 | ||
| 296 | | 参数名 | 类型 | 必填 | 说明 | | 296 | | 参数名 | 类型 | 必填 | 说明 | |
| 297 | | ------ | ------ | ---- | -------------------------- | | 297 | | ------ | ------ | ---- | -------------------------- | |
| 298 | -| enable | boolean | 是 | 表示静态订阅事件使能状态。 true:使能 false:去使能。 | | 298 | +| enable | boolean | 是 | 表示静态订阅事件使能状态。true:使能,false:去使能。 | |
| 299 | 299 | ||
| 300 | **返回值:** | 300 | **返回值:** |
| 301 | 301 | ||
| @@ -322,8 +322,8 @@ import { BusinessError } from '@kit.BasicServicesKit'; | |||
| 322 | 322 | ||
| 323 | commonEventManager.setStaticSubscriberState(false).then(() => { | 323 | commonEventManager.setStaticSubscriberState(false).then(() => { |
| 324 | console.info(`setStaticSubscriberState success`); | 324 | console.info(`setStaticSubscriberState success`); |
| 325 | -}).catch ((err: BusinessError) => { | 325 | +}).catch((err: BusinessError) => { |
| 326 | - console.error(`setStaticSubscriberState failed, errCode: ${err.code}, errMes: ${err.message}`); | 326 | + console.error(`setStaticSubscriberState failed, errCode: ${err.code}, errMsg: ${err.message}`); |
| 327 | }); | 327 | }); |
| 328 | ``` | 328 | ``` |
| 329 | 329 | ||
| @@ -331,7 +331,7 @@ commonEventManager.setStaticSubscriberState(false).then(() => { | |||
| 331 | 331 | ||
| 332 | setStaticSubscriberState(enable: boolean, events?: Array\<string>): Promise\<void> | 332 | setStaticSubscriberState(enable: boolean, events?: Array\<string>): Promise\<void> |
| 333 | 333 | ||
| 334 | -为当前应用设置静态订阅事件的使能状态,并且记录事件名称。使用Promise异步回调。 | 334 | +设置当前应用的静态订阅公共事件的使能状态。使用Promise异步回调。 |
| 335 | 335 | ||
| 336 | **模型约束**:此接口仅可在Stage模型下使用。 | 336 | **模型约束**:此接口仅可在Stage模型下使用。 |
| 337 | 337 | ||
| @@ -343,8 +343,8 @@ setStaticSubscriberState(enable: boolean, events?: Array\<string>): Promise\<voi | |||
| 343 | 343 | ||
| 344 | | 参数名 | 类型 | 必填 | 说明 | | 344 | | 参数名 | 类型 | 必填 | 说明 | |
| 345 | | ------ | ------------- | ---- | ---------------------------------------------------- | | 345 | | ------ | ------------- | ---- | ---------------------------------------------------- | |
| 346 | -| enable | boolean | 是 | 表示静态订阅事件使能状态。 true:使能 false:去使能。| | 346 | +| enable | boolean | 是 | 表示静态订阅事件使能状态。true:使能,false:去使能。| |
| 347 | -| events | Array\<string> | 否 | 表示记录事件名称。 | | 347 | +| events | Array\<string> | 否 | 表示需要设置的公共事件名称列表,默认为空列表,表示设置当前应用所有的静态订阅公共事件状态。 | |
| 348 | 348 | ||
| 349 | **返回值:** | 349 | **返回值:** |
| 350 | 350 | ||
| @@ -368,10 +368,10 @@ setStaticSubscriberState(enable: boolean, events?: Array\<string>): Promise\<voi | |||
| 368 | ```ts | 368 | ```ts |
| 369 | import { BusinessError } from '@kit.BasicServicesKit'; | 369 | import { BusinessError } from '@kit.BasicServicesKit'; |
| 370 | 370 | ||
| 371 | -let evenName: string[] = ['usual.event.SEND_DATA']; | 371 | +let eventName: string[] = ['usual.event.SEND_DATA']; |
| 372 | -commonEventManager.setStaticSubscriberState(true, evenName).then(() => { | 372 | +commonEventManager.setStaticSubscriberState(true, eventName).then(() => { |
| 373 | - console.info(`setStaticSubscriberState success, state is ${true}`); | 373 | + console.info(`setStaticSubscriberState success`); |
| 374 | }).catch((err: BusinessError) => { | 374 | }).catch((err: BusinessError) => { |
| 375 | - console.error(`setStaticSubscriberState failed, errCode: ${err.code}, errMes: ${err.message}`); | 375 | + console.error(`setStaticSubscriberState failed, errCode: ${err.code}, errMsg: ${err.message}`); |
| 376 | }); | 376 | }); |
| 377 | ``` | 377 | ``` |
| @@ -6,7 +6,33 @@ | |||
| 6 | <!--Tester: @wanghong1997--> | 6 | <!--Tester: @wanghong1997--> |
| 7 | <!--Adviser: @fang-jinxu--> | 7 | <!--Adviser: @fang-jinxu--> |
| 8 | 8 | ||
| 9 | -本模块提供了公共事件相关的能力,包括发布公共事件、订阅公共事件、以及退订公共事件。 | 9 | +本模块提供公共事件的发布、订阅、取消订阅等能力。公共事件是一种系统级的事件通知机制,允许应用在系统状态变化(如开机完成、电量变化、屏幕亮灭等)或业务自定义事件发生时,向订阅了该事件的应用发送通知,实现跨组件、跨应用的信息传递。 |
| 10 | + | ||
| 11 | +本模块涉及的关键概念: | ||
| 12 | +- 系统公共事件:是由系统服务或系统应用发布的预置公共事件,对应`Support`枚举中定义的事件名称,部分系统公共事件的订阅需要特定权限。 | ||
| 13 | +- 有序公共事件:是按订阅者优先级依次投递的公共事件,高优先级订阅者先收到事件,可通过修改事件数据将信息传递给后续订阅者,也可中止向低优先级订阅者投递事件。 | ||
| 14 | + | ||
| 15 | +**API 组合使用关系说明:** | ||
| 16 | + | ||
| 17 | +本模块的事件通信遵循三条组合调用链:订阅流、发布流与有序事件流。其中订阅流与发布流通过事件名称关联,发布者与订阅者无需感知对方存在。 | ||
| 18 | + | ||
| 19 | +**订阅流:创建订阅者 → 注册订阅 → 接收事件 → 取消订阅** | ||
| 20 | + | ||
| 21 | +1. 配置订阅者信息,声明订阅的事件名称,可选设置订阅优先级、发布方权限与包名。 | ||
| 22 | +2. 通过`commonEventManager.createSubscriberSync`创建订阅者对象。 | ||
| 23 | +3. 通过`commonEventManager.subscribe`注册订阅,事件发布时通过回调接收`CommonEventData`,在回调中处理事件数据。 | ||
| 24 | +4. 不再需要时,通过`commonEventManager.unsubscribe`取消订阅。 | ||
| 25 | + | ||
| 26 | +**发布流:发布事件(可选携带数据与属性)** | ||
| 27 | + | ||
| 28 | +1. 简单发布:通过`commonEventManager.publish`仅指定事件名发布事件。 | ||
| 29 | +2. 携带数据与属性发布:通过`CommonEventPublishData`配置code、data、parameters及`isOrdered`等属性,再调用`publish`发布。 | ||
| 30 | + | ||
| 31 | +**有序事件流:按优先级顺序投递 + 订阅者协作** | ||
| 32 | + | ||
| 33 | +1. 通过`CommonEventPublishData`将`isOrdered`设为`true`,调用`publish`发布有序事件,事件按订阅者优先级依次投递。 | ||
| 34 | +2. 高优先级订阅者先收到事件,可在回调中通过`setCodeAndData`等方法修改code与data数据,供后续订阅者接收。 | ||
| 35 | +3. 处理完成后调用`finishCommonEvent`,触发事件向下一优先级订阅者投递;若需中止后续投递,可调用`abortCommonEvent`标记事件为中止状态。 | ||
| 10 | 36 | ||
| 11 | > **说明:** | 37 | > **说明:** |
| 12 | > | 38 | > |
| @@ -20,7 +46,7 @@ import { commonEventManager } from '@kit.BasicServicesKit'; | |||
| 20 | 46 | ||
| 21 | ## Support | 47 | ## Support |
| 22 | 48 | ||
| 23 | -系统公共事件是指由系统服务或系统应用发布的事件,订阅这些公共事件需要特定的权限、使用相应的值,详见[系统定义的公共事件](./common_event/commonEventManager-definitions.md)。 | 49 | +系统公共事件是指由系统服务或系统应用发布的事件,订阅这些公共事件需要特定的权限,并使用相应的事件值,详见[系统定义的公共事件](./common_event/commonEventManager-definitions.md)。 |
| 24 | 50 | ||
| 25 | ## commonEventManager.publish | 51 | ## commonEventManager.publish |
| 26 | 52 | ||
| @@ -36,7 +62,7 @@ publish(event: string, callback: AsyncCallback\<void>): void | |||
| 36 | 62 | ||
| 37 | | 参数名 | 类型 | 必填 | 说明 | | 63 | | 参数名 | 类型 | 必填 | 说明 | |
| 38 | | -------- | -------------------- | ---- | ---------------------- | | 64 | | -------- | -------------------- | ---- | ---------------------- | |
| 39 | -| event | string | 是 | 表示要发送的公共事件。详见[系统定义的公共事件](./common_event/commonEventManager-definitions.md)。 | | 65 | +| event | string | 是 | 表示要发布的公共事件。详见[系统定义的公共事件](./common_event/commonEventManager-definitions.md)。 | |
| 40 | | callback | AsyncCallback\<void> | 是 | 回调函数。当公共事件发布成功时,err为undefined,否则为错误对象。 | | 66 | | callback | AsyncCallback\<void> | 是 | 回调函数。当公共事件发布成功时,err为undefined,否则为错误对象。 | |
| 41 | 67 | ||
| 42 | **错误码:** | 68 | **错误码:** |
| @@ -109,7 +135,7 @@ let options: commonEventManager.CommonEventPublishData = { | |||
| 109 | code: 0, | 135 | code: 0, |
| 110 | data: 'initial data', | 136 | data: 'initial data', |
| 111 | isOrdered: true // 有序公共事件 | 137 | isOrdered: true // 有序公共事件 |
| 112 | -} | 138 | +}; |
| 113 | 139 | ||
| 114 | // 发布公共事件 | 140 | // 发布公共事件 |
| 115 | try { | 141 | try { |
| @@ -141,7 +167,7 @@ createSubscriber(subscribeInfo: CommonEventSubscribeInfo, callback: AsyncCallbac | |||
| 141 | | 参数名 | 类型 | 必填 | 说明 | | 167 | | 参数名 | 类型 | 必填 | 说明 | |
| 142 | | ------------- | ------------------------------------------------------------ | ---- | -------------------------- | | 168 | | ------------- | ------------------------------------------------------------ | ---- | -------------------------- | |
| 143 | | subscribeInfo | [CommonEventSubscribeInfo](./js-apis-inner-commonEvent-commonEventSubscribeInfo.md) | 是 | 表示订阅信息。 | | 169 | | subscribeInfo | [CommonEventSubscribeInfo](./js-apis-inner-commonEvent-commonEventSubscribeInfo.md) | 是 | 表示订阅信息。 | |
| 144 | -| callback | AsyncCallback\<[CommonEventSubscriber](./js-apis-inner-commonEvent-commonEventSubscriber.md#commoneventsubscriber-1)> | 是 | 回调函数。当公共事件订阅者创建成功时,err为undefined,否则为错误对象。 | | 170 | +| callback | AsyncCallback\<[CommonEventSubscriber](./js-apis-inner-commonEvent-commonEventSubscriber.md#commoneventsubscriber-1)> | 是 | 回调函数,用于接收创建的订阅者对象。当公共事件订阅者创建成功时,err为undefined,data为创建成功的CommonEventSubscriber订阅者对象;否则err为错误对象 | |
| 145 | 171 | ||
| 146 | **错误码:** | 172 | **错误码:** |
| 147 | 173 | ||
| @@ -156,7 +182,7 @@ createSubscriber(subscribeInfo: CommonEventSubscribeInfo, callback: AsyncCallbac | |||
| 156 | ```ts | 182 | ```ts |
| 157 | import { BusinessError } from '@kit.BasicServicesKit'; | 183 | import { BusinessError } from '@kit.BasicServicesKit'; |
| 158 | 184 | ||
| 159 | -// 定义订阅者,用于保存创建成功的订阅者对象,后续使用其完成订阅及退订的动作 | 185 | +// 定义订阅者,用于保存创建成功的订阅者对象,后续使用其完成订阅及取消订阅的动作 |
| 160 | let subscriber: commonEventManager.CommonEventSubscriber | null = null; | 186 | let subscriber: commonEventManager.CommonEventSubscriber | null = null; |
| 161 | // 订阅者信息 | 187 | // 订阅者信息 |
| 162 | let subscribeInfo: commonEventManager.CommonEventSubscribeInfo = { | 188 | let subscribeInfo: commonEventManager.CommonEventSubscribeInfo = { |
| @@ -167,7 +193,7 @@ let subscribeInfo: commonEventManager.CommonEventSubscribeInfo = { | |||
| 167 | try { | 193 | try { |
| 168 | commonEventManager.createSubscriber(subscribeInfo, | 194 | commonEventManager.createSubscriber(subscribeInfo, |
| 169 | (err: BusinessError, commonEventSubscriber: commonEventManager.CommonEventSubscriber) => { | 195 | (err: BusinessError, commonEventSubscriber: commonEventManager.CommonEventSubscriber) => { |
| 170 | - if(!err) { | 196 | + if (!err) { |
| 171 | console.info(`Succeeded in creating subscriber.`); | 197 | console.info(`Succeeded in creating subscriber.`); |
| 172 | subscriber = commonEventSubscriber; | 198 | subscriber = commonEventSubscriber; |
| 173 | return; | 199 | return; |
| @@ -214,7 +240,7 @@ createSubscriber(subscribeInfo: CommonEventSubscribeInfo): Promise\<CommonEventS | |||
| 214 | ```ts | 240 | ```ts |
| 215 | import { BusinessError } from '@kit.BasicServicesKit'; | 241 | import { BusinessError } from '@kit.BasicServicesKit'; |
| 216 | 242 | ||
| 217 | -// 定义订阅者,用于保存创建成功的订阅者对象,后续使用其完成订阅及退订的动作 | 243 | +// 定义订阅者,用于保存创建成功的订阅者对象,后续使用其完成订阅及取消订阅的动作 |
| 218 | let subscriber: commonEventManager.CommonEventSubscriber | null = null; | 244 | let subscriber: commonEventManager.CommonEventSubscriber | null = null; |
| 219 | // 订阅者信息 | 245 | // 订阅者信息 |
| 220 | let subscribeInfo: commonEventManager.CommonEventSubscribeInfo = { | 246 | let subscribeInfo: commonEventManager.CommonEventSubscribeInfo = { |
| @@ -233,7 +259,7 @@ commonEventManager.createSubscriber(subscribeInfo).then((commonEventSubscriber: | |||
| 233 | 259 | ||
| 234 | createSubscriberSync(subscribeInfo: CommonEventSubscribeInfo): CommonEventSubscriber | 260 | createSubscriberSync(subscribeInfo: CommonEventSubscribeInfo): CommonEventSubscriber |
| 235 | 261 | ||
| 236 | -createSubscriber的同步接口。 | 262 | +同步创建订阅者的接口。 |
| 237 | 263 | ||
| 238 | **原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 | 264 | **原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 |
| 239 | 265 | ||
| @@ -263,7 +289,7 @@ createSubscriber的同步接口。 | |||
| 263 | ```ts | 289 | ```ts |
| 264 | import { BusinessError } from '@kit.BasicServicesKit'; | 290 | import { BusinessError } from '@kit.BasicServicesKit'; |
| 265 | 291 | ||
| 266 | -// 定义订阅者,用于保存创建成功的订阅者对象,后续使用其完成订阅及退订的动作 | 292 | +// 定义订阅者,用于保存创建成功的订阅者对象,后续使用其完成订阅及取消订阅的动作 |
| 267 | let subscriber: commonEventManager.CommonEventSubscriber | null = null; | 293 | let subscriber: commonEventManager.CommonEventSubscriber | null = null; |
| 268 | // 订阅者信息 | 294 | // 订阅者信息 |
| 269 | let subscribeInfo: commonEventManager.CommonEventSubscribeInfo = { | 295 | let subscribeInfo: commonEventManager.CommonEventSubscribeInfo = { |
| @@ -293,7 +319,7 @@ subscribe(subscriber: CommonEventSubscriber, callback: AsyncCallback\<CommonEven | |||
| 293 | | 参数名 | 类型 | 必填 | 说明 | | 319 | | 参数名 | 类型 | 必填 | 说明 | |
| 294 | | ---------- | ---------------------------------------------------- | ---- | -------------------------------- | | 320 | | ---------- | ---------------------------------------------------- | ---- | -------------------------------- | |
| 295 | | subscriber | [CommonEventSubscriber](./js-apis-inner-commonEvent-commonEventSubscriber.md#commoneventsubscriber-1) | 是 | 表示订阅者对象。 | | 321 | | subscriber | [CommonEventSubscriber](./js-apis-inner-commonEvent-commonEventSubscriber.md#commoneventsubscriber-1) | 是 | 表示订阅者对象。 | |
| 296 | -| callback | AsyncCallback\<[CommonEventData](./js-apis-inner-commonEvent-commonEventData.md)> | 是 | 回调函数。当公共事件订阅成功后,事件触发时执行的回调函数;否则订阅失败时,err为错误对象。 | | 322 | +| callback | AsyncCallback\<[CommonEventData](./js-apis-inner-commonEvent-commonEventData.md)> | 是 | 回调函数。当公共事件订阅成功后,事件触发时通过data返回公共事件数据;订阅失败时,err为错误对象。 | |
| 297 | 323 | ||
| 298 | **错误码:** | 324 | **错误码:** |
| 299 | 325 | ||
| @@ -301,7 +327,7 @@ subscribe(subscriber: CommonEventSubscriber, callback: AsyncCallback\<CommonEven | |||
| 301 | 327 | ||
| 302 | | 错误码ID | 错误信息 | | 328 | | 错误码ID | 错误信息 | |
| 303 | | -------- | ----------------------------------- | | 329 | | -------- | ----------------------------------- | |
| 304 | -| 801 | capability not supported. | | 330 | +| 801 | Capability not supported. | |
| 305 | | 1500007 | Failed to send the message to the common event service. | | 331 | | 1500007 | Failed to send the message to the common event service. | |
| 306 | | 1500008 | Failed to initialize the common event service. | | 332 | | 1500008 | Failed to initialize the common event service. | |
| 307 | | 1500010 | The count of subscriber exceed system specification. <br> 适用版本:20+| | 333 | | 1500010 | The count of subscriber exceed system specification. <br> 适用版本:20+| |
| @@ -311,7 +337,7 @@ subscribe(subscriber: CommonEventSubscriber, callback: AsyncCallback\<CommonEven | |||
| 311 | ```ts | 337 | ```ts |
| 312 | import { BusinessError } from '@kit.BasicServicesKit'; | 338 | import { BusinessError } from '@kit.BasicServicesKit'; |
| 313 | 339 | ||
| 314 | -// 定义订阅者,用于保存创建成功的订阅者对象,后续使用其完成订阅及退订的动作 | 340 | +// 定义订阅者,用于保存创建成功的订阅者对象,后续使用其完成订阅及取消订阅的动作 |
| 315 | let subscriber: commonEventManager.CommonEventSubscriber | null = null; | 341 | let subscriber: commonEventManager.CommonEventSubscriber | null = null; |
| 316 | // 订阅者信息 | 342 | // 订阅者信息 |
| 317 | let subscribeInfo: commonEventManager.CommonEventSubscribeInfo = { | 343 | let subscribeInfo: commonEventManager.CommonEventSubscribeInfo = { |
| @@ -322,7 +348,7 @@ let subscribeInfo: commonEventManager.CommonEventSubscribeInfo = { | |||
| 322 | try { | 348 | try { |
| 323 | commonEventManager.createSubscriber(subscribeInfo, | 349 | commonEventManager.createSubscriber(subscribeInfo, |
| 324 | (err: BusinessError, commonEventSubscriber: commonEventManager.CommonEventSubscriber) => { | 350 | (err: BusinessError, commonEventSubscriber: commonEventManager.CommonEventSubscriber) => { |
| 325 | - if(!err) { | 351 | + if (!err) { |
| 326 | console.info(`Succeeded in creating subscriber.`); | 352 | console.info(`Succeeded in creating subscriber.`); |
| 327 | subscriber = commonEventSubscriber; | 353 | subscriber = commonEventSubscriber; |
| 328 | // 订阅公共事件 | 354 | // 订阅公共事件 |
| @@ -363,7 +389,7 @@ unsubscribe(subscriber: CommonEventSubscriber, callback?: AsyncCallback\<void>): | |||
| 363 | | 参数名 | 类型 | 必填 | 说明 | | 389 | | 参数名 | 类型 | 必填 | 说明 | |
| 364 | | ---------- | ----------------------------------------------- | ---- | ------------------------ | | 390 | | ---------- | ----------------------------------------------- | ---- | ------------------------ | |
| 365 | | subscriber | [CommonEventSubscriber](./js-apis-inner-commonEvent-commonEventSubscriber.md#commoneventsubscriber-1) | 是 | 表示订阅者对象。 | | 391 | | subscriber | [CommonEventSubscriber](./js-apis-inner-commonEvent-commonEventSubscriber.md#commoneventsubscriber-1) | 是 | 表示订阅者对象。 | |
| 366 | -| callback | AsyncCallback\<void> | 否 | 回调函数。当取消公共事件订阅成功时,err为undefined,否则为错误对象。 | | 392 | +| callback | AsyncCallback\<void> | 否 | 回调函数。当取消公共事件订阅成功时,err为undefined,否则为错误对象。不传该参数时,默认取消订阅且不返回结果。 | |
| 367 | 393 | ||
| 368 | **错误码:** | 394 | **错误码:** |
| 369 | 395 | ||
| @@ -372,7 +398,7 @@ unsubscribe(subscriber: CommonEventSubscriber, callback?: AsyncCallback\<void>): | |||
| 372 | | 错误码ID | 错误信息 | | 398 | | 错误码ID | 错误信息 | |
| 373 | | -------- | ----------------------------------- | | 399 | | -------- | ----------------------------------- | |
| 374 | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | | 400 | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | |
| 375 | -| 801 | capability not supported. | | 401 | +| 801 | Capability not supported. | |
| 376 | | 1500007 | Failed to send the message to the common event service. | | 402 | | 1500007 | Failed to send the message to the common event service. | |
| 377 | | 1500008 | Failed to initialize the common event service. | | 403 | | 1500008 | Failed to initialize the common event service. | |
| 378 | 404 | ||
| @@ -381,7 +407,7 @@ unsubscribe(subscriber: CommonEventSubscriber, callback?: AsyncCallback\<void>): | |||
| 381 | ```ts | 407 | ```ts |
| 382 | import { BusinessError } from '@kit.BasicServicesKit'; | 408 | import { BusinessError } from '@kit.BasicServicesKit'; |
| 383 | 409 | ||
| 384 | -// 定义订阅者,用于保存创建成功的订阅者对象,后续使用其完成订阅及退订的动作 | 410 | +// 定义订阅者,用于保存创建成功的订阅者对象,后续使用其完成订阅及取消订阅的动作 |
| 385 | let subscriber: commonEventManager.CommonEventSubscriber | null = null; | 411 | let subscriber: commonEventManager.CommonEventSubscriber | null = null; |
| 386 | // 订阅者信息 | 412 | // 订阅者信息 |
| 387 | let subscribeInfo: commonEventManager.CommonEventSubscribeInfo = { | 413 | let subscribeInfo: commonEventManager.CommonEventSubscribeInfo = { |
| @@ -392,7 +418,7 @@ let subscribeInfo: commonEventManager.CommonEventSubscribeInfo = { | |||
| 392 | try { | 418 | try { |
| 393 | commonEventManager.createSubscriber(subscribeInfo, | 419 | commonEventManager.createSubscriber(subscribeInfo, |
| 394 | (err: BusinessError, commonEventSubscriber: commonEventManager.CommonEventSubscriber) => { | 420 | (err: BusinessError, commonEventSubscriber: commonEventManager.CommonEventSubscriber) => { |
| 395 | - if(!err) { | 421 | + if (!err) { |
| 396 | console.info(`Succeeded in creating subscriber.`); | 422 | console.info(`Succeeded in creating subscriber.`); |
| 397 | subscriber = commonEventSubscriber; | 423 | subscriber = commonEventSubscriber; |
| 398 | // 订阅公共事件 | 424 | // 订阅公共事件 |
| @@ -475,11 +501,11 @@ subscribeToEvent(subscriber: CommonEventSubscriber, callback: Callback\<CommonEv | |||
| 475 | ```ts | 501 | ```ts |
| 476 | import { BusinessError } from '@kit.BasicServicesKit'; | 502 | import { BusinessError } from '@kit.BasicServicesKit'; |
| 477 | 503 | ||
| 478 | -// 定义订阅者,用于保存创建成功的订阅者对象,后续使用其完成订阅及退订的动作 | 504 | +// 定义订阅者,用于保存创建成功的订阅者对象,后续使用其完成订阅及取消订阅的动作 |
| 479 | let subscriber: commonEventManager.CommonEventSubscriber | null = null; | 505 | let subscriber: commonEventManager.CommonEventSubscriber | null = null; |
| 480 | // 订阅者信息 | 506 | // 订阅者信息 |
| 481 | let subscribeInfo: commonEventManager.CommonEventSubscribeInfo = { | 507 | let subscribeInfo: commonEventManager.CommonEventSubscribeInfo = { |
| 482 | - events: ["event"] | 508 | + events: ['event'] |
| 483 | }; | 509 | }; |
| 484 | 510 | ||
| 485 | // 创建订阅者 | 511 | // 创建订阅者 |
| @@ -494,9 +520,9 @@ try { | |||
| 494 | // 订阅公共事件 | 520 | // 订阅公共事件 |
| 495 | try { | 521 | try { |
| 496 | commonEventManager.subscribeToEvent(subscriber, (data: commonEventManager.CommonEventData) => { | 522 | commonEventManager.subscribeToEvent(subscriber, (data: commonEventManager.CommonEventData) => { |
| 497 | - console.info(`Succeeded to receive common event, data is ` + JSON.stringify(data)); | 523 | + console.info(`Succeeded to receive common event, data is ${JSON.stringify(data)}`); |
| 498 | }).then(() => { | 524 | }).then(() => { |
| 499 | - console.info(`Succeeded to subscribe.`); | 525 | + console.info(`Succeeded in subscribing.`); |
| 500 | }).catch((err: BusinessError) => { | 526 | }).catch((err: BusinessError) => { |
| 501 | console.error(`Failed to subscribe. Code is ${err.code}, message is ${err.message}`); | 527 | console.error(`Failed to subscribe. Code is ${err.code}, message is ${err.message}`); |
| 502 | }); | 528 | }); |
| @@ -516,7 +542,7 @@ try { | |||
| 516 | 542 | ||
| 517 | type CommonEventData = _CommonEventData | 543 | type CommonEventData = _CommonEventData |
| 518 | 544 | ||
| 519 | -表示公共事件的数据。 | 545 | +描述公共事件的数据。 |
| 520 | 546 | ||
| 521 | **原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 | 547 | **原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 |
| 522 | 548 | ||
| @@ -544,7 +570,7 @@ type CommonEventSubscriber = _CommonEventSubscriber | |||
| 544 | 570 | ||
| 545 | type CommonEventSubscribeInfo = _CommonEventSubscribeInfo | 571 | type CommonEventSubscribeInfo = _CommonEventSubscribeInfo |
| 546 | 572 | ||
| 547 | -用于表示订阅者的信息。 | 573 | +描述公共事件订阅者的信息。 |
| 548 | 574 | ||
| 549 | **原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 | 575 | **原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 |
| 550 | 576 | ||
| @@ -6,7 +6,20 @@ | |||
| 6 | <!--Tester: @wanghong1997--> | 6 | <!--Tester: @wanghong1997--> |
| 7 | <!--Adviser: @fang-jinxu--> | 7 | <!--Adviser: @fang-jinxu--> |
| 8 | 8 | ||
| 9 | -本模块提供了在同一进程不同线程间或同一线程内发送和处理事件的能力,支持持续订阅事件、单次订阅事件、取消订阅事件及发送事件到事件队列。 | 9 | +本模块提供进程内线程间或线程内事件的发送与处理能力。开发者可以使用本模块的 API,订阅事件(持续订阅或单次订阅)、取消订阅事件,发送事件到事件队列中,以及查询事件的订阅数量,从而实现同一进程内不同线程之间、以及同一线程内的事件通信。 |
| 10 | + | ||
| 11 | +提供两种事件处理入口,开发者可根据隔离需求选择: | ||
| 12 | + | ||
| 13 | +- **命名空间级 API**(`emitter` 命名空间下的 `on`、`once`、`off`、`emit`、`getListenerCount` 等函数):提供进程内全局范围的事件订阅与发布能力。该入口基于全局事件队列工作,同进程内任意线程均可订阅和发布事件,适用于跨线程事件通信。 | ||
| 14 | +- **实例级 API**(`Emitter` 类):提供同一 `Emitter` 实例范围内的事件订阅与发布能力。不同 `Emitter` 实例之间相互隔离,开发者可创建多个独立的事件通信通道,适用于需要事件隔离或按实例分组的场景。 | ||
| 15 | + | ||
| 16 | +**API 组合使用关系说明:** | ||
| 17 | + | ||
| 18 | +本模块的事件通信遵循"订阅 → 发布 → 处理 → 取消订阅"的组合调用模式。无论是命名空间级 API 还是实例级 API,均需先订阅事件,再由其他线程或同一线程发布事件,收到事件后执行回调处理;当不再需要接收事件时,应取消订阅以释放资源。同时,事件订阅具有明确的生命周期,开发者应注意资源管理: | ||
| 19 | + | ||
| 20 | +- **持续订阅**(`on`):订阅后持续有效,直至调用 `off` 取消订阅。若未取消,订阅将一直保留。 | ||
| 21 | +- **单次订阅**(`once`):订阅后,仅在首次接收到事件并执行回调后自动取消,无需手动调用 `off`。 | ||
| 22 | +- **取消订阅的时机**:调用 `off` 取消订阅后,已通过 `emit` 发布但尚未执行的事件也将被取消,不再触发回调。同时需要注意,取消指定回调时,需传入对应的 `callback` 函数;若未指定,表示取消该事件的所有订阅。 | ||
| 10 | 23 | ||
| 11 | > **说明:** | 24 | > **说明:** |
| 12 | > | 25 | > |
| @@ -26,13 +39,13 @@ on(event: InnerEvent, callback: Callback\<EventData\>): void | |||
| 26 | 39 | ||
| 27 | **原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 | 40 | **原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 |
| 28 | 41 | ||
| 29 | -**系统能力**:`SystemCapability.Notification.Emitter` | 42 | +**系统能力:** SystemCapability.Notification.Emitter |
| 30 | 43 | ||
| 31 | **参数:** | 44 | **参数:** |
| 32 | 45 | ||
| 33 | | 参数名 | 类型 | 必填 | 说明 | | 46 | | 参数名 | 类型 | 必填 | 说明 | |
| 34 | | -------- | ----------------------------------- | ---- | ------------------------------------------------------------ | | 47 | | -------- | ----------------------------------- | ---- | ------------------------------------------------------------ | |
| 35 | -| event | [InnerEvent](#innerevent) | 是 | 持续订阅的事件,其中[EventPriority](#eventpriority),在订阅事件时无需指定,也不生效。 | | 48 | +| event | [InnerEvent](#innerevent) | 是 | 持续订阅的事件,其中[EventPriority](#eventpriority)在订阅事件时无需指定,也不生效。 | |
| 36 | | callback | Callback\<[EventData](#eventdata)\> | 是 | 接收到该事件时需要执行的回调处理函数。 | | 49 | | callback | Callback\<[EventData](#eventdata)\> | 是 | 接收到该事件时需要执行的回调处理函数。 | |
| 37 | 50 | ||
| 38 | **示例:** | 51 | **示例:** |
| @@ -46,27 +59,27 @@ let innerEvent: emitter.InnerEvent = { | |||
| 46 | 59 | ||
| 47 | let callback: Callback<emitter.EventData> = (eventData: emitter.EventData) => { | 60 | let callback: Callback<emitter.EventData> = (eventData: emitter.EventData) => { |
| 48 | console.info(`eventData: ${JSON.stringify(eventData)}`); | 61 | console.info(`eventData: ${JSON.stringify(eventData)}`); |
| 49 | -} | 62 | +}; |
| 50 | 63 | ||
| 51 | -// 收到eventId为1的事件后执行回调函数 | 64 | +// 收到eventId为1的事件后执行回调处理函数 |
| 52 | emitter.on(innerEvent, callback); | 65 | emitter.on(innerEvent, callback); |
| 53 | ``` | 66 | ``` |
| 54 | 67 | ||
| 55 | ## emitter.on<sup>11+</sup> | 68 | ## emitter.on<sup>11+</sup> |
| 56 | 69 | ||
| 57 | -on(eventId: string, callback: Callback\<EventData\>): void | 70 | +on(eventId: string, callback: Callback\<EventData\>): void |
| 58 | 71 | ||
| 59 | 持续订阅指定的事件,并在接收到该事件时,执行对应的回调处理函数。 | 72 | 持续订阅指定的事件,并在接收到该事件时,执行对应的回调处理函数。 |
| 60 | 73 | ||
| 61 | **原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 | 74 | **原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 |
| 62 | 75 | ||
| 63 | -**系统能力**:`SystemCapability.Notification.Emitter` | 76 | +**系统能力:** SystemCapability.Notification.Emitter |
| 64 | 77 | ||
| 65 | **参数:** | 78 | **参数:** |
| 66 | 79 | ||
| 67 | | 参数名 | 类型 | 必填 | 说明 | | 80 | | 参数名 | 类型 | 必填 | 说明 | |
| 68 | | -------- | ----------------------------------- | ---- | -------------------------------------- | | 81 | | -------- | ----------------------------------- | ---- | -------------------------------------- | |
| 69 | -| eventId | string | 是 | 持续订阅的事件。取值为长度不超过10240字节的自定义字符串,且不可为空字符。 | | 82 | +| eventId | string | 是 | 持续订阅的事件ID。<br>不可为空字符串,大小不超过10240字节,超出部分会被截断。 | |
| 70 | | callback | Callback\<[EventData](#eventdata)\> | 是 | 接收到该事件时需要执行的回调处理函数。 | | 83 | | callback | Callback\<[EventData](#eventdata)\> | 是 | 接收到该事件时需要执行的回调处理函数。 | |
| 71 | 84 | ||
| 72 | **示例:** | 85 | **示例:** |
| @@ -76,26 +89,26 @@ import { Callback } from '@kit.BasicServicesKit'; | |||
| 76 | 89 | ||
| 77 | let callback: Callback<emitter.EventData> = (eventData: emitter.EventData) => { | 90 | let callback: Callback<emitter.EventData> = (eventData: emitter.EventData) => { |
| 78 | console.info(`eventData: ${JSON.stringify(eventData)}`); | 91 | console.info(`eventData: ${JSON.stringify(eventData)}`); |
| 79 | -} | 92 | +}; |
| 80 | -// 收到eventId为"eventId"的事件后执行回调函数 | 93 | +// 收到eventId为"eventId"的事件后执行回调处理函数 |
| 81 | -emitter.on(`eventId`, callback); | 94 | +emitter.on('eventId', callback); |
| 82 | ``` | 95 | ``` |
| 83 | 96 | ||
| 84 | ## emitter.on<sup>12+</sup> | 97 | ## emitter.on<sup>12+</sup> |
| 85 | 98 | ||
| 86 | -on<T\>(eventId: string, callback: Callback\<GenericEventData<T\>\>): void | 99 | +on<T\>(eventId: string, callback: Callback\<GenericEventData<T\>\>): void |
| 87 | 100 | ||
| 88 | 持续订阅指定的事件,并在接收到该事件时,执行对应的回调处理函数。 | 101 | 持续订阅指定的事件,并在接收到该事件时,执行对应的回调处理函数。 |
| 89 | 102 | ||
| 90 | **原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 | 103 | **原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 |
| 91 | 104 | ||
| 92 | -**系统能力**:`SystemCapability.Notification.Emitter` | 105 | +**系统能力:** SystemCapability.Notification.Emitter |
| 93 | 106 | ||
| 94 | **参数:** | 107 | **参数:** |
| 95 | 108 | ||
| 96 | | 参数名 | 类型 | 必填 | 说明 | | 109 | | 参数名 | 类型 | 必填 | 说明 | |
| 97 | | -------- | ----------------------------------- | ---- | -------------------------------------- | | 110 | | -------- | ----------------------------------- | ---- | -------------------------------------- | |
| 98 | -| eventId | string | 是 | 持续订阅的事件。取值为长度不超过10240字节的自定义字符串,且不可为空字符。 | | 111 | +| eventId | string | 是 | 持续订阅的事件ID。<br>不可为空字符串,大小不超过10240字节,超出部分会被截断。 | |
| 99 | | callback | Callback\<[GenericEventData<T\>](#genericeventdatat12)\> | 是 | 接收到该事件时需要执行的回调处理函数。 | | 112 | | callback | Callback\<[GenericEventData<T\>](#genericeventdatat12)\> | 是 | 接收到该事件时需要执行的回调处理函数。 | |
| 100 | 113 | ||
| 101 | **示例:** | 114 | **示例:** |
| @@ -119,26 +132,26 @@ let callback: Callback<emitter.GenericEventData<Sample>> = (eventData: emitter.G | |||
| 119 | if (eventData?.data instanceof Sample) { | 132 | if (eventData?.data instanceof Sample) { |
| 120 | eventData?.data?.printCount(); | 133 | eventData?.data?.printCount(); |
| 121 | } | 134 | } |
| 122 | -} | 135 | +}; |
| 123 | // 收到eventId为"eventId"的事件后执行回调函数 | 136 | // 收到eventId为"eventId"的事件后执行回调函数 |
| 124 | -emitter.on("eventId", callback); | 137 | +emitter.on('eventId', callback); |
| 125 | ``` | 138 | ``` |
| 126 | 139 | ||
| 127 | ## emitter.once | 140 | ## emitter.once |
| 128 | 141 | ||
| 129 | once(event: InnerEvent, callback: Callback\<EventData\>): void | 142 | once(event: InnerEvent, callback: Callback\<EventData\>): void |
| 130 | 143 | ||
| 131 | -单次订阅指定的事件,在接收到该事件且执行完对应的回调函数后,自动取消订阅。 | 144 | +单次订阅指定的事件,在接收到该事件且执行完对应的回调处理函数后,自动取消订阅。 |
| 132 | 145 | ||
| 133 | **原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 | 146 | **原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 |
| 134 | 147 | ||
| 135 | -**系统能力**:`SystemCapability.Notification.Emitter` | 148 | +**系统能力:** SystemCapability.Notification.Emitter |
| 136 | 149 | ||
| 137 | **参数:** | 150 | **参数:** |
| 138 | 151 | ||
| 139 | | 参数名 | 类型 | 必填 | 说明 | | 152 | | 参数名 | 类型 | 必填 | 说明 | |
| 140 | | -------- | ----------------------------------- | ---- | ------------------------------------------------------------ | | 153 | | -------- | ----------------------------------- | ---- | ------------------------------------------------------------ | |
| 141 | -| event | [InnerEvent](#innerevent) | 是 | 单次订阅的事件,其中[EventPriority](#eventpriority),在订阅事件时无需指定,也不生效。 | | 154 | +| event | [InnerEvent](#innerevent) | 是 | 单次订阅的事件,其中[EventPriority](#eventpriority)在订阅事件时无需指定,也不生效。 | |
| 142 | | callback | Callback\<[EventData](#eventdata)\> | 是 | 接收到该事件时需要执行的回调处理函数。 | | 155 | | callback | Callback\<[EventData](#eventdata)\> | 是 | 接收到该事件时需要执行的回调处理函数。 | |
| 143 | 156 | ||
| 144 | **示例:** | 157 | **示例:** |
| @@ -152,8 +165,8 @@ let innerEvent: emitter.InnerEvent = { | |||
| 152 | 165 | ||
| 153 | let callback: Callback<emitter.EventData> = (eventData: emitter.EventData) => { | 166 | let callback: Callback<emitter.EventData> = (eventData: emitter.EventData) => { |
| 154 | console.info(`eventData: ${JSON.stringify(eventData)}`); | 167 | console.info(`eventData: ${JSON.stringify(eventData)}`); |
| 155 | -} | 168 | +}; |
| 156 | -// 收到eventId为1的事件后执行该回调函数 | 169 | +// 收到eventId为1的事件后执行该回调处理函数 |
| 157 | emitter.once(innerEvent, callback); | 170 | emitter.once(innerEvent, callback); |
| 158 | ``` | 171 | ``` |
| 159 | 172 | ||
| @@ -161,17 +174,17 @@ emitter.once(innerEvent, callback); | |||
| 161 | 174 | ||
| 162 | once(eventId: string, callback: Callback\<EventData\>): void | 175 | once(eventId: string, callback: Callback\<EventData\>): void |
| 163 | 176 | ||
| 164 | -单次订阅指定的事件,在接收到该事件且执行完对应的回调函数后,自动取消订阅。 | 177 | +单次订阅指定的事件,在接收到该事件且执行完对应的回调处理函数后,自动取消订阅。 |
| 165 | 178 | ||
| 166 | **原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 | 179 | **原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 |
| 167 | 180 | ||
| 168 | -**系统能力**:`SystemCapability.Notification.Emitter` | 181 | +**系统能力:** SystemCapability.Notification.Emitter |
| 169 | 182 | ||
| 170 | **参数:** | 183 | **参数:** |
| 171 | 184 | ||
| 172 | | 参数名 | 类型 | 必填 | 说明 | | 185 | | 参数名 | 类型 | 必填 | 说明 | |
| 173 | | -------- | ----------------------------------- | ---- | -------------------------------------- | | 186 | | -------- | ----------------------------------- | ---- | -------------------------------------- | |
| 174 | -| eventId | string | 是 | 单次订阅的事件。取值为长度不超过10240字节的自定义字符串,且不可为空字符。 | | 187 | +| eventId | string | 是 | 单次订阅的事件ID。<br>不可为空字符串,大小不超过10240字节,超出部分会被截断。 | |
| 175 | | callback | Callback\<[EventData](#eventdata)\> | 是 | 接收到该事件时需要执行的回调处理函数。 | | 188 | | callback | Callback\<[EventData](#eventdata)\> | 是 | 接收到该事件时需要执行的回调处理函数。 | |
| 176 | 189 | ||
| 177 | **示例:** | 190 | **示例:** |
| @@ -181,26 +194,26 @@ import { Callback } from '@kit.BasicServicesKit'; | |||
| 181 | 194 | ||
| 182 | let callback: Callback<emitter.EventData> = (eventData: emitter.EventData) => { | 195 | let callback: Callback<emitter.EventData> = (eventData: emitter.EventData) => { |
| 183 | console.info(`eventData: ${JSON.stringify(eventData)}`); | 196 | console.info(`eventData: ${JSON.stringify(eventData)}`); |
| 184 | -} | 197 | +}; |
| 185 | // 收到eventId为"eventId"的事件后执行该回调函数 | 198 | // 收到eventId为"eventId"的事件后执行该回调函数 |
| 186 | -emitter.once("eventId", callback); | 199 | +emitter.once('eventId', callback); |
| 187 | ``` | 200 | ``` |
| 188 | 201 | ||
| 189 | ## emitter.once<sup>12+</sup> | 202 | ## emitter.once<sup>12+</sup> |
| 190 | 203 | ||
| 191 | once<T\>(eventId: string, callback: Callback\<GenericEventData<T\>\>): void | 204 | once<T\>(eventId: string, callback: Callback\<GenericEventData<T\>\>): void |
| 192 | 205 | ||
| 193 | -单次订阅指定的事件,在接收到该事件且执行完相应的回调函数后,自动取消订阅。 | 206 | +单次订阅指定的事件,在接收到该事件且执行完对应的回调处理函数后,自动取消订阅。 |
| 194 | 207 | ||
| 195 | **原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 | 208 | **原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 |
| 196 | 209 | ||
| 197 | -**系统能力**:`SystemCapability.Notification.Emitter` | 210 | +**系统能力:** SystemCapability.Notification.Emitter |
| 198 | 211 | ||
| 199 | **参数:** | 212 | **参数:** |
| 200 | 213 | ||
| 201 | | 参数名 | 类型 | 必填 | 说明 | | 214 | | 参数名 | 类型 | 必填 | 说明 | |
| 202 | | -------- | ----------------------------------- | ---- | -------------------------------------- | | 215 | | -------- | ----------------------------------- | ---- | -------------------------------------- | |
| 203 | -| eventId | string | 是 | 单次订阅的事件。取值为长度不超过10240字节的自定义字符串,且不可为空字符。 | | 216 | +| eventId | string | 是 | 单次订阅的事件ID。<br>不可为空字符串,大小不超过10240字节,超出部分会被截断。 | |
| 204 | | callback | Callback\<[GenericEventData<T\>](#genericeventdatat12)\> | 是 | 接收到该事件时需要执行的回调处理函数。 | | 217 | | callback | Callback\<[GenericEventData<T\>](#genericeventdatat12)\> | 是 | 接收到该事件时需要执行的回调处理函数。 | |
| 205 | 218 | ||
| 206 | **示例:** | 219 | **示例:** |
| @@ -224,9 +237,9 @@ let callback: Callback<emitter.GenericEventData<Sample>> = (eventData: emitter.G | |||
| 224 | if (eventData?.data instanceof Sample) { | 237 | if (eventData?.data instanceof Sample) { |
| 225 | eventData?.data?.printCount(); | 238 | eventData?.data?.printCount(); |
| 226 | } | 239 | } |
| 227 | -} | 240 | +}; |
| 228 | // 收到eventId为"eventId"的事件后执行回调函数 | 241 | // 收到eventId为"eventId"的事件后执行回调函数 |
| 229 | -emitter.once("eventId", callback); | 242 | +emitter.once('eventId', callback); |
| 230 | ``` | 243 | ``` |
| 231 | 244 | ||
| 232 | ## emitter.off | 245 | ## emitter.off |
| @@ -239,13 +252,13 @@ off(eventId: number): void | |||
| 239 | 252 | ||
| 240 | **原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 | 253 | **原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 |
| 241 | 254 | ||
| 242 | -**系统能力**:`SystemCapability.Notification.Emitter` | 255 | +**系统能力:** SystemCapability.Notification.Emitter |
| 243 | 256 | ||
| 244 | **参数:** | 257 | **参数:** |
| 245 | 258 | ||
| 246 | | 参数名 | 类型 | 必填 | 说明 | | 259 | | 参数名 | 类型 | 必填 | 说明 | |
| 247 | | ------- | ------ | ---- | -------- | | 260 | | ------- | ------ | ---- | -------- | |
| 248 | -| eventId | number | 是 | 事件ID。 | | 261 | +| eventId | number | 是 | 事件ID,由开发者定义,用于辨别事件。 | |
| 249 | 262 | ||
| 250 | **示例:** | 263 | **示例:** |
| 251 | 264 | ||
| @@ -264,13 +277,13 @@ off(eventId: string): void | |||
| 264 | 277 | ||
| 265 | **原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 | 278 | **原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 |
| 266 | 279 | ||
| 267 | -**系统能力**:`SystemCapability.Notification.Emitter` | 280 | +**系统能力:** SystemCapability.Notification.Emitter |
| 268 | 281 | ||
| 269 | **参数:** | 282 | **参数:** |
| 270 | 283 | ||
| 271 | | 参数名 | 类型 | 必填 | 说明 | | 284 | | 参数名 | 类型 | 必填 | 说明 | |
| 272 | | ------- | ------ | ---- | -------- | | 285 | | ------- | ------ | ---- | -------- | |
| 273 | -| eventId | string | 是 | 事件ID。取值为长度不超过10240字节的自定义字符串,且不可为空字符。 | | 286 | +| eventId | string | 是 | 事件ID。<br>不可为空字符串,大小不超过10240字节,超出部分会被截断。 | |
| 274 | 287 | ||
| 275 | **示例:** | 288 | **示例:** |
| 276 | 289 | ||
| @@ -289,14 +302,14 @@ off(eventId: number, callback: Callback\<EventData\>): void | |||
| 289 | 302 | ||
| 290 | **原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 | 303 | **原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 |
| 291 | 304 | ||
| 292 | -**系统能力**:`SystemCapability.Notification.Emitter` | 305 | +**系统能力:** SystemCapability.Notification.Emitter |
| 293 | 306 | ||
| 294 | **参数:** | 307 | **参数:** |
| 295 | 308 | ||
| 296 | | 参数名 | 类型 | 必填 | 说明 | | 309 | | 参数名 | 类型 | 必填 | 说明 | |
| 297 | | ------- | ------ | ---- | ------ | | 310 | | ------- | ------ | ---- | ------ | |
| 298 | -| eventId | number | 是 | 事件ID。 | | 311 | +| eventId | number | 是 | 事件ID,由开发者定义,用于辨别事件。 | |
| 299 | -| callback | Callback\<[EventData](#eventdata)\> | 是 | 事件的回调处理函数。 | | 312 | +| callback | Callback\<[EventData](#eventdata)\> | 是 | 回调函数,指定要取消订阅的事件处理函数,需与订阅时使用的callback一致。 | |
| 300 | 313 | ||
| 301 | **示例:** | 314 | **示例:** |
| 302 | 315 | ||
| @@ -305,7 +318,7 @@ import { Callback } from '@kit.BasicServicesKit'; | |||
| 305 | 318 | ||
| 306 | let callback: Callback<emitter.EventData> = (eventData: emitter.EventData) => { | 319 | let callback: Callback<emitter.EventData> = (eventData: emitter.EventData) => { |
| 307 | console.info(`eventData: ${JSON.stringify(eventData)}`); | 320 | console.info(`eventData: ${JSON.stringify(eventData)}`); |
| 308 | -} | 321 | +}; |
| 309 | // 取消eventId为1的事件回调处理函数,callback对象应使用订阅时的对象 | 322 | // 取消eventId为1的事件回调处理函数,callback对象应使用订阅时的对象 |
| 310 | // 如果该回调处理函数没有被订阅,则不做任何处理 | 323 | // 如果该回调处理函数没有被订阅,则不做任何处理 |
| 311 | emitter.off(1, callback); | 324 | emitter.off(1, callback); |
| @@ -321,14 +334,14 @@ off(eventId: string, callback: Callback\<EventData\>): void | |||
| 321 | 334 | ||
| 322 | **原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 | 335 | **原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 |
| 323 | 336 | ||
| 324 | -**系统能力**:`SystemCapability.Notification.Emitter` | 337 | +**系统能力:** SystemCapability.Notification.Emitter |
| 325 | 338 | ||
| 326 | **参数:** | 339 | **参数:** |
| 327 | 340 | ||
| 328 | | 参数名 | 类型 | 必填 | 说明 | | 341 | | 参数名 | 类型 | 必填 | 说明 | |
| 329 | | -------- | ----------------------------------- | ---- | -------------------------- | | 342 | | -------- | ----------------------------------- | ---- | -------------------------- | |
| 330 | -| eventId | string | 是 | 事件ID。取值为长度不超过10240字节的自定义字符串,且不可为空字符。 | | 343 | +| eventId | string | 是 | 事件ID。<br>不可为空字符串,大小不超过10240字节,超出部分会被截断。 | |
| 331 | -| callback | Callback\<[EventData](#eventdata)\> | 是 | 事件的回调处理函数。 | | 344 | +| callback | Callback\<[EventData](#eventdata)\> | 是 | 回调函数,指定要取消订阅的事件处理函数,需与订阅时使用的callback一致。 | |
| 332 | 345 | ||
| 333 | **示例:** | 346 | **示例:** |
| 334 | 347 | ||
| @@ -337,7 +350,7 @@ import { Callback } from '@kit.BasicServicesKit'; | |||
| 337 | 350 | ||
| 338 | let callback: Callback<emitter.EventData> = (eventData: emitter.EventData) => { | 351 | let callback: Callback<emitter.EventData> = (eventData: emitter.EventData) => { |
| 339 | console.info(`eventData: ${JSON.stringify(eventData)}`); | 352 | console.info(`eventData: ${JSON.stringify(eventData)}`); |
| 340 | -} | 353 | +}; |
| 341 | // 取消eventId为"eventId1"的事件回调处理函数,callback对象应使用订阅时的对象 | 354 | // 取消eventId为"eventId1"的事件回调处理函数,callback对象应使用订阅时的对象 |
| 342 | // 如果该回调处理函数没有被订阅,则不做任何处理 | 355 | // 如果该回调处理函数没有被订阅,则不做任何处理 |
| 343 | emitter.off("eventId1", callback); | 356 | emitter.off("eventId1", callback); |
| @@ -353,14 +366,14 @@ off<T\>(eventId: string, callback: Callback\<GenericEventData<T\>\>): void | |||
| 353 | 366 | ||
| 354 | **原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 | 367 | **原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 |
| 355 | 368 | ||
| 356 | -**系统能力**:`SystemCapability.Notification.Emitter` | 369 | +**系统能力:** SystemCapability.Notification.Emitter |
| 357 | 370 | ||
| 358 | **参数:** | 371 | **参数:** |
| 359 | 372 | ||
| 360 | | 参数名 | 类型 | 必填 | 说明 | | 373 | | 参数名 | 类型 | 必填 | 说明 | |
| 361 | | -------- | ----------------------------------- | ---- | -------------------------- | | 374 | | -------- | ----------------------------------- | ---- | -------------------------- | |
| 362 | -| eventId | string | 是 | 事件ID。取值为长度不超过10240字节的自定义字符串,且不可为空字符。 | | 375 | +| eventId | string | 是 | 事件ID。<br>不可为空字符串,大小不超过10240字节,超出部分会被截断。 | |
| 363 | -| callback | Callback\<[GenericEventData<T\>](#genericeventdatat12)\> | 是 | 事件的回调处理函数。 | | 376 | +| callback | Callback\<[GenericEventData<T\>](#genericeventdatat12)\> | 是 | 回调函数,指定要取消订阅的事件处理函数,需与订阅时使用的callback一致。 | |
| 364 | 377 | ||
| 365 | **示例:** | 378 | **示例:** |
| 366 | 379 | ||
| @@ -383,7 +396,7 @@ let callback: Callback<emitter.GenericEventData<Sample>> = (eventData: emitter.G | |||
| 383 | if (eventData?.data instanceof Sample) { | 396 | if (eventData?.data instanceof Sample) { |
| 384 | eventData?.data?.printCount(); | 397 | eventData?.data?.printCount(); |
| 385 | } | 398 | } |
| 386 | -} | 399 | +}; |
| 387 | // 取消eventId为"eventId1"的事件回调处理函数,callback对象应使用订阅时的对象 | 400 | // 取消eventId为"eventId1"的事件回调处理函数,callback对象应使用订阅时的对象 |
| 388 | // 如果该回调处理函数没有被订阅,则不做任何处理 | 401 | // 如果该回调处理函数没有被订阅,则不做任何处理 |
| 389 | emitter.off("eventId1", callback); | 402 | emitter.off("eventId1", callback); |
| @@ -401,7 +414,7 @@ emit(event: InnerEvent, data?: EventData): void | |||
| 401 | 414 | ||
| 402 | **原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 | 415 | **原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 |
| 403 | 416 | ||
| 404 | -**系统能力**:`SystemCapability.Notification.Emitter` | 417 | +**系统能力:** SystemCapability.Notification.Emitter |
| 405 | 418 | ||
| 406 | **参数:** | 419 | **参数:** |
| 407 | 420 | ||
| @@ -440,13 +453,13 @@ emit(eventId: string, data?: EventData): void | |||
| 440 | 453 | ||
| 441 | **原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 | 454 | **原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 |
| 442 | 455 | ||
| 443 | -**系统能力**:`SystemCapability.Notification.Emitter` | 456 | +**系统能力:** SystemCapability.Notification.Emitter |
| 444 | 457 | ||
| 445 | **参数:** | 458 | **参数:** |
| 446 | 459 | ||
| 447 | | 参数名 | 类型 | 必填 | 说明 | | 460 | | 参数名 | 类型 | 必填 | 说明 | |
| 448 | | ------- | ----------------------- | ---- | ---------------- | | 461 | | ------- | ----------------------- | ---- | ---------------- | |
| 449 | -| eventId | string | 是 | 发送的事件ID。取值为长度不超过10240字节的自定义字符串,且不可为空字符。 | | 462 | +| eventId | string | 是 | 发送的事件ID。<br>不可为空字符串,大小不超过10240字节,超出部分会被截断。 | |
| 450 | | data | [EventData](#eventdata) | 否 | 事件携带的数据,默认为空。 | | 463 | | data | [EventData](#eventdata) | 否 | 事件携带的数据,默认为空。 | |
| 451 | 464 | ||
| 452 | **示例:** | 465 | **示例:** |
| @@ -454,12 +467,12 @@ emit(eventId: string, data?: EventData): void | |||
| 454 | ```ts | 467 | ```ts |
| 455 | let eventData: emitter.EventData = { | 468 | let eventData: emitter.EventData = { |
| 456 | data: { | 469 | data: { |
| 457 | - "content": "content", | 470 | + "content": "content", |
| 458 | - "id": 1, | 471 | + "id": 1, |
| 459 | } | 472 | } |
| 460 | }; | 473 | }; |
| 461 | 474 | ||
| 462 | -emitter.emit("eventId", eventData); | 475 | +emitter.emit('eventId', eventData); |
| 463 | ``` | 476 | ``` |
| 464 | 477 | ||
| 465 | ## emitter.emit<sup>12+</sup> | 478 | ## emitter.emit<sup>12+</sup> |
| @@ -474,13 +487,13 @@ emit<T\>(eventId: string, data?: GenericEventData<T\>): void | |||
| 474 | 487 | ||
| 475 | **原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 | 488 | **原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 |
| 476 | 489 | ||
| 477 | -**系统能力**:`SystemCapability.Notification.Emitter` | 490 | +**系统能力:** SystemCapability.Notification.Emitter |
| 478 | 491 | ||
| 479 | **参数:** | 492 | **参数:** |
| 480 | 493 | ||
| 481 | | 参数名 | 类型 | 必填 | 说明 | | 494 | | 参数名 | 类型 | 必填 | 说明 | |
| 482 | | ------- | ----------------------- | ---- | ---------------- | | 495 | | ------- | ----------------------- | ---- | ---------------- | |
| 483 | -| eventId | string | 是 | 发送的事件ID。取值为长度不超过10240字节的自定义字符串,且不可为空字符。 | | 496 | +| eventId | string | 是 | 发送的事件ID。<br>不可为空字符串,大小不超过10240字节,超出部分会被截断。 | |
| 484 | | data | [GenericEventData<T\>](#genericeventdatat12) | 否 | 事件携带的数据,默认为空。 | | 497 | | data | [GenericEventData<T\>](#genericeventdatat12) | 否 | 事件携带的数据,默认为空。 | |
| 485 | 498 | ||
| 486 | **示例:** | 499 | **示例:** |
| @@ -500,7 +513,7 @@ class Sample { | |||
| 500 | let eventData: emitter.GenericEventData<Sample> = { | 513 | let eventData: emitter.GenericEventData<Sample> = { |
| 501 | data: new Sample() | 514 | data: new Sample() |
| 502 | }; | 515 | }; |
| 503 | -emitter.emit("eventId", eventData); | 516 | +emitter.emit('eventId', eventData); |
| 504 | ``` | 517 | ``` |
| 505 | 518 | ||
| 506 | ## emitter.emit<sup>11+</sup> | 519 | ## emitter.emit<sup>11+</sup> |
| @@ -515,13 +528,13 @@ emit(eventId: string, options: Options, data?: EventData): void | |||
| 515 | 528 | ||
| 516 | **原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 | 529 | **原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 |
| 517 | 530 | ||
| 518 | -**系统能力**:`SystemCapability.Notification.Emitter` | 531 | +**系统能力:** SystemCapability.Notification.Emitter |
| 519 | 532 | ||
| 520 | **参数:** | 533 | **参数:** |
| 521 | 534 | ||
| 522 | | 参数名 | 类型 | 必填 | 说明 | | 535 | | 参数名 | 类型 | 必填 | 说明 | |
| 523 | | ------- | ----------------------- | ---- | ---------------- | | 536 | | ------- | ----------------------- | ---- | ---------------- | |
| 524 | -| eventId | string | 是 | 发送的事件ID。取值为长度不超过10240字节的自定义字符串,且不可为空字符。 | | 537 | +| eventId | string | 是 | 发送的事件ID。<br>不可为空字符串,大小不超过10240字节,超出部分会被截断。 | |
| 525 | | options | [Options](#options11) | 是 | 事件优先级。 | | 538 | | options | [Options](#options11) | 是 | 事件优先级。 | |
| 526 | | data | [EventData](#eventdata) | 否 | 事件携带的数据,默认为空。 | | 539 | | data | [EventData](#eventdata) | 否 | 事件携带的数据,默认为空。 | |
| 527 | 540 | ||
| @@ -539,7 +552,7 @@ let options: emitter.Options = { | |||
| 539 | priority: emitter.EventPriority.HIGH | 552 | priority: emitter.EventPriority.HIGH |
| 540 | }; | 553 | }; |
| 541 | 554 | ||
| 542 | -emitter.emit("eventId", options, eventData); | 555 | +emitter.emit('eventId', options, eventData); |
| 543 | ``` | 556 | ``` |
| 544 | 557 | ||
| 545 | ## emitter.emit<sup>12+</sup> | 558 | ## emitter.emit<sup>12+</sup> |
| @@ -554,13 +567,13 @@ emit<T\>(eventId: string, options: Options, data?: GenericEventData<T\>): void | |||
| 554 | 567 | ||
| 555 | **原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 | 568 | **原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 |
| 556 | 569 | ||
| 557 | -**系统能力**:`SystemCapability.Notification.Emitter` | 570 | +**系统能力:** SystemCapability.Notification.Emitter |
| 558 | 571 | ||
| 559 | **参数:** | 572 | **参数:** |
| 560 | 573 | ||
| 561 | | 参数名 | 类型 | 必填 | 说明 | | 574 | | 参数名 | 类型 | 必填 | 说明 | |
| 562 | | ------- | ----------------------- | ---- | ---------------- | | 575 | | ------- | ----------------------- | ---- | ---------------- | |
| 563 | -| eventId | string | 是 | 发送的事件ID。取值为长度不超过10240字节的自定义字符串,且不可为空字符。 | | 576 | +| eventId | string | 是 | 发送的事件ID。<br>不可为空字符串,大小不超过10240字节,超出部分会被截断。 | |
| 564 | | options | [Options](#options11) | 是 | 事件优先级。 | | 577 | | options | [Options](#options11) | 是 | 事件优先级。 | |
| 565 | | data | [GenericEventData<T\>](#genericeventdatat12) | 否 | 事件携带的数据,默认为空。 | | 578 | | data | [GenericEventData<T\>](#genericeventdatat12) | 否 | 事件携带的数据,默认为空。 | |
| 566 | 579 | ||
| @@ -585,7 +598,7 @@ let eventData: emitter.GenericEventData<Sample> = { | |||
| 585 | data: new Sample() | 598 | data: new Sample() |
| 586 | }; | 599 | }; |
| 587 | 600 | ||
| 588 | -emitter.emit("eventId", options, eventData); | 601 | +emitter.emit('eventId', options, eventData); |
| 589 | ``` | 602 | ``` |
| 590 | 603 | ||
| 591 | ## emitter.getListenerCount<sup>11+</sup> | 604 | ## emitter.getListenerCount<sup>11+</sup> |
| @@ -596,13 +609,13 @@ getListenerCount(eventId: number | string): number | |||
| 596 | 609 | ||
| 597 | **原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 | 610 | **原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 |
| 598 | 611 | ||
| 599 | -**系统能力**:`SystemCapability.Notification.Emitter` | 612 | +**系统能力:** SystemCapability.Notification.Emitter |
| 600 | 613 | ||
| 601 | **参数:** | 614 | **参数:** |
| 602 | 615 | ||
| 603 | | 参数名 | 类型 | 必填 | 说明 | | 616 | | 参数名 | 类型 | 必填 | 说明 | |
| 604 | | ------- | -------------- | ---- | -------- | | 617 | | ------- | -------------- | ---- | -------- | |
| 605 | -| eventId | number \| string | 是 | 事件ID,string类型的eventId取值为长度不超过10240字节的自定义字符串,且不可为空字符。 | | 618 | +| eventId | number \| string | 是 | 事件ID,由开发者定义,用于辨别事件。<br> string类型:不可为空字符串,大小不超过10240字节,超出部分会被截断。| |
| 606 | 619 | ||
| 607 | **返回值:** | 620 | **返回值:** |
| 608 | 621 | ||
| @@ -614,7 +627,7 @@ getListenerCount(eventId: number | string): number | |||
| 614 | **示例:** | 627 | **示例:** |
| 615 | 628 | ||
| 616 | ```ts | 629 | ```ts |
| 617 | -let count: number = emitter.getListenerCount("eventId"); | 630 | +let count: number = emitter.getListenerCount('eventId'); |
| 618 | ``` | 631 | ``` |
| 619 | 632 | ||
| 620 | ## EventPriority | 633 | ## EventPriority |
| @@ -623,13 +636,13 @@ let count: number = emitter.getListenerCount("eventId"); | |||
| 623 | 636 | ||
| 624 | **原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 | 637 | **原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 |
| 625 | 638 | ||
| 626 | -**系统能力**: `SystemCapability.Notification.Emitter` | 639 | +**系统能力:** SystemCapability.Notification.Emitter |
| 627 | 640 | ||
| 628 | | 名称 | 值 | 说明 | | 641 | | 名称 | 值 | 说明 | |
| 629 | | --------- | ---- | --------------------------------------------------- | | 642 | | --------- | ---- | --------------------------------------------------- | |
| 630 | | IMMEDIATE | 0 | 表示事件先于HIGH优先级投递。 | | 643 | | IMMEDIATE | 0 | 表示事件先于HIGH优先级投递。 | |
| 631 | | HIGH | 1 | 表示事件先于LOW优先级投递。 | | 644 | | HIGH | 1 | 表示事件先于LOW优先级投递。 | |
| 632 | -| LOW | 2 | 表示事件优于IDLE优先级投递,事件的默认优先级是LOW。 | | 645 | +| LOW | 2 | 表示事件先于IDLE优先级投递,事件的默认优先级是LOW。 | |
| 633 | | IDLE | 3 | 表示在没有其他事件的情况下,才投递该事件。 | | 646 | | IDLE | 3 | 表示在没有其他事件的情况下,才投递该事件。 | |
| 634 | 647 | ||
| 635 | ## InnerEvent | 648 | ## InnerEvent |
| @@ -638,7 +651,7 @@ let count: number = emitter.getListenerCount("eventId"); | |||
| 638 | 651 | ||
| 639 | **原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 | 652 | **原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 |
| 640 | 653 | ||
| 641 | -**系统能力**:`SystemCapability.Notification.Emitter` | 654 | +**系统能力:** SystemCapability.Notification.Emitter |
| 642 | 655 | ||
| 643 | | 名称 | 类型 | 只读 | 可选 | 说明 | | 656 | | 名称 | 类型 | 只读 | 可选 | 说明 | |
| 644 | | -------- | ------------------------------- | ---- | ---- | ------------------------------ | | 657 | | -------- | ------------------------------- | ---- | ---- | ------------------------------ | |
| @@ -651,11 +664,11 @@ let count: number = emitter.getListenerCount("eventId"); | |||
| 651 | 664 | ||
| 652 | **原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 | 665 | **原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 |
| 653 | 666 | ||
| 654 | -**系统能力**:`SystemCapability.Notification.Emitter` | 667 | +**系统能力:** SystemCapability.Notification.Emitter |
| 655 | 668 | ||
| 656 | | 名称 | 类型 | 只读 | 可选 | 说明 | | 669 | | 名称 | 类型 | 只读 | 可选 | 说明 | |
| 657 | | ---- | ------------------ | ---- | ---- | -------------- | | 670 | | ---- | ------------------ | ---- | ---- | -------------- | |
| 658 | -| data | { [key: string]: any } | 否 | 是 | 发送事件时传递的数据,支持数据类型包括Array、ArrayBuffer、Boolean、DataView、Date、Error、Map、Number、Object、Primitive(除了symbol)、RegExp、Set、String、TypedArray,数据大小最大为16M。 | | 671 | +| data | { [key: string]: any } | 否 | 是 | 发送事件时传递的数据,支持数据类型包括Array、ArrayBuffer、Boolean、DataView、Date、Error、Map、Number、Object、Primitive(除了symbol)、RegExp、Set、String、TypedArray,数据大小最大为16MB,超出限制时事件发送失败。 | |
| 659 | 672 | ||
| 660 | ## Options<sup>11+</sup> | 673 | ## Options<sup>11+</sup> |
| 661 | 674 | ||
| @@ -663,7 +676,7 @@ let count: number = emitter.getListenerCount("eventId"); | |||
| 663 | 676 | ||
| 664 | **原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 | 677 | **原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 |
| 665 | 678 | ||
| 666 | -**系统能力**:`SystemCapability.Notification.Emitter` | 679 | +**系统能力:** SystemCapability.Notification.Emitter |
| 667 | 680 | ||
| 668 | | 名称 | 类型 | 只读 | 可选 | 说明 | | 681 | | 名称 | 类型 | 只读 | 可选 | 说明 | |
| 669 | | -------- | ------------------------------- | ---- | ---- | -------------- | | 682 | | -------- | ------------------------------- | ---- | ---- | -------------- | |
| @@ -675,20 +688,20 @@ let count: number = emitter.getListenerCount("eventId"); | |||
| 675 | 688 | ||
| 676 | **原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 | 689 | **原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 |
| 677 | 690 | ||
| 678 | -**系统能力**:`SystemCapability.Notification.Emitter` | 691 | +**系统能力:** SystemCapability.Notification.Emitter |
| 679 | 692 | ||
| 680 | | 名称 | 类型 | 只读 | 可选 | 说明 | | 693 | | 名称 | 类型 | 只读 | 可选 | 说明 | |
| 681 | | -------- | ------------------------------- | ---- | ---- | -------------- | | 694 | | -------- | ------------------------------- | ---- | ---- | -------------- | |
| 682 | -| data | T | 否 | 是 | 发送事件时传递的数据。T:泛型类型。 | | 695 | +| data | T | 否 | 是 | 发送事件时传递的数据。T:泛型类型,由开发者根据业务需要自定义具体的数据类型。 | |
| 683 | 696 | ||
| 684 | 697 | ||
| 685 | ## Emitter<sup>22+</sup> | 698 | ## Emitter<sup>22+</sup> |
| 686 | 699 | ||
| 687 | -该功能支持在同一进程的同一Emitter类实例中,跨不同线程或同一线程内发送和处理事件。它能够实现持续订阅事件、单次订阅事件、取消订阅事件以及将事件发送到事件队列。 | 700 | +该功能支持在同一进程的同一Emitter类实例中,跨不同线程或同一线程内发送和处理事件。它能够实现持续订阅事件、单次订阅事件、取消订阅事件以及将事件发送到事件队列,适用于需要基于独立实例进行线程间通信和事件管理的场景,不同Emitter实例类之间相互隔离,互不影响。 |
| 688 | 701 | ||
| 689 | **原子化服务API:** 从API version 22开始,该接口支持在原子化服务中使用。 | 702 | **原子化服务API:** 从API version 22开始,该接口支持在原子化服务中使用。 |
| 690 | 703 | ||
| 691 | -**系统能力:** `SystemCapability.Notification.Emitter` | 704 | +**系统能力:** SystemCapability.Notification.Emitter |
| 692 | 705 | ||
| 693 | ### constructor<sup>22+</sup> | 706 | ### constructor<sup>22+</sup> |
| 694 | 707 | ||
| @@ -698,7 +711,7 @@ constructor() | |||
| 698 | 711 | ||
| 699 | **原子化服务API:** 从API version 22开始,该接口支持在原子化服务中使用。 | 712 | **原子化服务API:** 从API version 22开始,该接口支持在原子化服务中使用。 |
| 700 | 713 | ||
| 701 | -**系统能力:** `SystemCapability.Notification.Emitter` | 714 | +**系统能力:** SystemCapability.Notification.Emitter |
| 702 | 715 | ||
| 703 | **示例:** | 716 | **示例:** |
| 704 | 717 | ||
| @@ -709,19 +722,19 @@ let emitter1: emitter.Emitter = new emitter.Emitter(); | |||
| 709 | 722 | ||
| 710 | ### on<sup>22+</sup> | 723 | ### on<sup>22+</sup> |
| 711 | 724 | ||
| 712 | -on(eventId: string, callback: Callback\<EventData\>): void | 725 | +on(eventId: string, callback: Callback\<EventData\>): void |
| 713 | 726 | ||
| 714 | 持续订阅当前Emitter类实例指定的事件,并在接收到该事件时,使用callback异步回调。 | 727 | 持续订阅当前Emitter类实例指定的事件,并在接收到该事件时,使用callback异步回调。 |
| 715 | 728 | ||
| 716 | **原子化服务API:** 从API version 22开始,该接口支持在原子化服务中使用。 | 729 | **原子化服务API:** 从API version 22开始,该接口支持在原子化服务中使用。 |
| 717 | 730 | ||
| 718 | -**系统能力**:`SystemCapability.Notification.Emitter` | 731 | +**系统能力:** SystemCapability.Notification.Emitter |
| 719 | 732 | ||
| 720 | **参数:** | 733 | **参数:** |
| 721 | 734 | ||
| 722 | | 参数名 | 类型 | 必填 | 说明 | | 735 | | 参数名 | 类型 | 必填 | 说明 | |
| 723 | | -------- | ----------------------------------- | ---- | -------------------------------------- | | 736 | | -------- | ----------------------------------- | ---- | -------------------------------------- | |
| 724 | -| eventId | string | 是 | 持续订阅的事件。取值为长度不超过10240字节的自定义字符串,且不可为空字符。 | | 737 | +| eventId | string | 是 | 持续订阅的事件ID。<br>不可为空字符串,大小不超过10240字节,超出部分会被截断。 | |
| 725 | | callback | Callback\<[EventData](#eventdata)\> | 是 | 回调函数,在接收到该事件时被调用。 | | 738 | | callback | Callback\<[EventData](#eventdata)\> | 是 | 回调函数,在接收到该事件时被调用。 | |
| 726 | 739 | ||
| 727 | **示例:** | 740 | **示例:** |
| @@ -733,26 +746,26 @@ let emitter1: emitter.Emitter = new emitter.Emitter(); | |||
| 733 | 746 | ||
| 734 | let callback: Callback<emitter.EventData> = (eventData: emitter.EventData) => { | 747 | let callback: Callback<emitter.EventData> = (eventData: emitter.EventData) => { |
| 735 | console.info(`eventData: ${JSON.stringify(eventData)}`); | 748 | console.info(`eventData: ${JSON.stringify(eventData)}`); |
| 736 | -} | 749 | +}; |
| 737 | 750 | ||
| 738 | -emitter1.on(`eventId`, callback); | 751 | +emitter1.on('eventId', callback); |
| 739 | ``` | 752 | ``` |
| 740 | 753 | ||
| 741 | ### on<sup>22+</sup> | 754 | ### on<sup>22+</sup> |
| 742 | 755 | ||
| 743 | -on<T\>(eventId: string, callback: Callback\<GenericEventData<T\>\>): void | 756 | +on<T\>(eventId: string, callback: Callback\<GenericEventData<T\>\>): void |
| 744 | 757 | ||
| 745 | 持续订阅当前Emitter类实例指定的事件,并在接收到该事件时,使用callback异步回调。 | 758 | 持续订阅当前Emitter类实例指定的事件,并在接收到该事件时,使用callback异步回调。 |
| 746 | 759 | ||
| 747 | **原子化服务API:** 从API version 22开始,该接口支持在原子化服务中使用。 | 760 | **原子化服务API:** 从API version 22开始,该接口支持在原子化服务中使用。 |
| 748 | 761 | ||
| 749 | -**系统能力**:`SystemCapability.Notification.Emitter` | 762 | +**系统能力:** SystemCapability.Notification.Emitter |
| 750 | 763 | ||
| 751 | **参数:** | 764 | **参数:** |
| 752 | 765 | ||
| 753 | | 参数名 | 类型 | 必填 | 说明 | | 766 | | 参数名 | 类型 | 必填 | 说明 | |
| 754 | | -------- | ----------------------------------- | ---- | -------------------------------------- | | 767 | | -------- | ----------------------------------- | ---- | -------------------------------------- | |
| 755 | -| eventId | string | 是 | 持续订阅的事件。取值为长度不超过10240字节的自定义字符串,且不可为空字符。 | | 768 | +| eventId | string | 是 | 持续订阅的事件ID。<br>不可为空字符串,大小不超过10240字节,超出部分会被截断。 | |
| 756 | | callback | Callback\<[GenericEventData<T\>](#genericeventdatat12)\> | 是 | 回调函数,在接收到该事件时被调用。 | | 769 | | callback | Callback\<[GenericEventData<T\>](#genericeventdatat12)\> | 是 | 回调函数,在接收到该事件时被调用。 | |
| 757 | 770 | ||
| 758 | **示例:** | 771 | **示例:** |
| @@ -778,26 +791,26 @@ let callback: Callback<emitter.GenericEventData<Sample>> = (eventData: emitter.G | |||
| 778 | if (eventData?.data instanceof Sample) { | 791 | if (eventData?.data instanceof Sample) { |
| 779 | eventData?.data?.printCount(); | 792 | eventData?.data?.printCount(); |
| 780 | } | 793 | } |
| 781 | -} | 794 | +}; |
| 782 | 795 | ||
| 783 | -emitter1.on("eventId", callback); | 796 | +emitter1.on('eventId', callback); |
| 784 | ``` | 797 | ``` |
| 785 | 798 | ||
| 786 | ### once<sup>22+</sup> | 799 | ### once<sup>22+</sup> |
| 787 | 800 | ||
| 788 | once(eventId: string, callback: Callback\<EventData\>): void | 801 | once(eventId: string, callback: Callback\<EventData\>): void |
| 789 | 802 | ||
| 790 | -单次订阅当前Emitter类实例指定的事件,在接收到该事件且执行完对应的回调函数后,自动取消订阅。使用callback异步回调。 | 803 | +单次订阅当前Emitter类实例指定的事件,在接收到该事件且执行完对应的回调处理函数后,自动取消订阅。使用callback异步回调。 |
| 791 | 804 | ||
| 792 | **原子化服务API:** 从API version 22开始,该接口支持在原子化服务中使用。 | 805 | **原子化服务API:** 从API version 22开始,该接口支持在原子化服务中使用。 |
| 793 | 806 | ||
| 794 | -**系统能力**:`SystemCapability.Notification.Emitter` | 807 | +**系统能力:** SystemCapability.Notification.Emitter |
| 795 | 808 | ||
| 796 | **参数:** | 809 | **参数:** |
| 797 | 810 | ||
| 798 | | 参数名 | 类型 | 必填 | 说明 | | 811 | | 参数名 | 类型 | 必填 | 说明 | |
| 799 | | -------- | ----------------------------------- | ---- | -------------------------------------- | | 812 | | -------- | ----------------------------------- | ---- | -------------------------------------- | |
| 800 | -| eventId | string | 是 | 单次订阅的事件。取值为长度不超过10240字节的自定义字符串,且不可为空字符。 | | 813 | +| eventId | string | 是 | 单次订阅的事件ID。<br>不可为空字符串,大小不超过10240字节,超出部分会被截断。 | |
| 801 | | callback | Callback\<[EventData](#eventdata)\> | 是 | 回调函数,在接收到该事件时被调用。 | | 814 | | callback | Callback\<[EventData](#eventdata)\> | 是 | 回调函数,在接收到该事件时被调用。 | |
| 802 | 815 | ||
| 803 | **示例:** | 816 | **示例:** |
| @@ -809,26 +822,26 @@ let emitter1: emitter.Emitter = new emitter.Emitter(); | |||
| 809 | 822 | ||
| 810 | let callback: Callback<emitter.EventData> = (eventData: emitter.EventData) => { | 823 | let callback: Callback<emitter.EventData> = (eventData: emitter.EventData) => { |
| 811 | console.info(`eventData: ${JSON.stringify(eventData)}`); | 824 | console.info(`eventData: ${JSON.stringify(eventData)}`); |
| 812 | -} | 825 | +}; |
| 813 | 826 | ||
| 814 | -emitter1.once("eventId", callback); | 827 | +emitter1.once('eventId', callback); |
| 815 | ``` | 828 | ``` |
| 816 | 829 | ||
| 817 | ### once<sup>22+</sup> | 830 | ### once<sup>22+</sup> |
| 818 | 831 | ||
| 819 | once<T\>(eventId: string, callback: Callback\<GenericEventData<T\>\>): void | 832 | once<T\>(eventId: string, callback: Callback\<GenericEventData<T\>\>): void |
| 820 | 833 | ||
| 821 | -单次订阅当前Emitter类实例指定的事件,在接收到该事件且执行完相应的回调函数后,自动取消订阅。使用callback异步回调。 | 834 | +单次订阅当前Emitter类实例指定的事件,在接收到该事件且执行完对应的回调处理函数后,自动取消订阅。使用callback异步回调。 |
| 822 | 835 | ||
| 823 | **原子化服务API:** 从API version 22开始,该接口支持在原子化服务中使用。 | 836 | **原子化服务API:** 从API version 22开始,该接口支持在原子化服务中使用。 |
| 824 | 837 | ||
| 825 | -**系统能力**:`SystemCapability.Notification.Emitter` | 838 | +**系统能力:** SystemCapability.Notification.Emitter |
| 826 | 839 | ||
| 827 | **参数:** | 840 | **参数:** |
| 828 | 841 | ||
| 829 | | 参数名 | 类型 | 必填 | 说明 | | 842 | | 参数名 | 类型 | 必填 | 说明 | |
| 830 | | -------- | ----------------------------------- | ---- | -------------------------------------- | | 843 | | -------- | ----------------------------------- | ---- | -------------------------------------- | |
| 831 | -| eventId | string | 是 | 单次订阅的事件。取值为长度不超过10240字节的自定义字符串,且不可为空字符。 | | 844 | +| eventId | string | 是 | 单次订阅的事件ID。<br>不可为空字符串,大小不超过10240字节,超出部分会被截断。 | |
| 832 | | callback | Callback\<[GenericEventData<T\>](#genericeventdatat12)\> | 是 | 回调函数,在接收到该事件时被调用。 | | 845 | | callback | Callback\<[GenericEventData<T\>](#genericeventdatat12)\> | 是 | 回调函数,在接收到该事件时被调用。 | |
| 833 | 846 | ||
| 834 | **示例:** | 847 | **示例:** |
| @@ -854,9 +867,9 @@ let callback: Callback<emitter.GenericEventData<Sample>> = (eventData: emitter.G | |||
| 854 | if (eventData?.data instanceof Sample) { | 867 | if (eventData?.data instanceof Sample) { |
| 855 | eventData?.data?.printCount(); | 868 | eventData?.data?.printCount(); |
| 856 | } | 869 | } |
| 857 | -} | 870 | +}; |
| 858 | 871 | ||
| 859 | -emitter1.once("eventId", callback); | 872 | +emitter1.once('eventId', callback); |
| 860 | ``` | 873 | ``` |
| 861 | 874 | ||
| 862 | ### off<sup>22+</sup> | 875 | ### off<sup>22+</sup> |
| @@ -869,20 +882,20 @@ off(eventId: string): void | |||
| 869 | 882 | ||
| 870 | **原子化服务API:** 从API version 22开始,该接口支持在原子化服务中使用。 | 883 | **原子化服务API:** 从API version 22开始,该接口支持在原子化服务中使用。 |
| 871 | 884 | ||
| 872 | -**系统能力**:`SystemCapability.Notification.Emitter` | 885 | +**系统能力:** SystemCapability.Notification.Emitter |
| 873 | 886 | ||
| 874 | **参数:** | 887 | **参数:** |
| 875 | 888 | ||
| 876 | | 参数名 | 类型 | 必填 | 说明 | | 889 | | 参数名 | 类型 | 必填 | 说明 | |
| 877 | | ------- | ------ | ---- | -------- | | 890 | | ------- | ------ | ---- | -------- | |
| 878 | -| eventId | string | 是 | 事件ID。取值为长度不超过10240字节的自定义字符串,且不可为空字符。 | | 891 | +| eventId | string | 是 | 事件ID。<br>不可为空字符串,大小不超过10240字节,超出部分会被截断。 | |
| 879 | 892 | ||
| 880 | **示例:** | 893 | **示例:** |
| 881 | 894 | ||
| 882 | ```ts | 895 | ```ts |
| 883 | let emitter1: emitter.Emitter = new emitter.Emitter(); | 896 | let emitter1: emitter.Emitter = new emitter.Emitter(); |
| 884 | 897 | ||
| 885 | -emitter1.off("eventId"); | 898 | +emitter1.off('eventId'); |
| 886 | ``` | 899 | ``` |
| 887 | 900 | ||
| 888 | ### off<sup>22+</sup> | 901 | ### off<sup>22+</sup> |
| @@ -891,17 +904,17 @@ off(eventId: string, callback: Callback\<EventData\>): void | |||
| 891 | 904 | ||
| 892 | 取消订阅当前Emitter类实例的事件。仅当已使用[on](#on22)或[once](#once22)接口订阅了事件ID为eventId且回调处理函数为callback的事件时,该接口才生效。 | 905 | 取消订阅当前Emitter类实例的事件。仅当已使用[on](#on22)或[once](#once22)接口订阅了事件ID为eventId且回调处理函数为callback的事件时,该接口才生效。 |
| 893 | 906 | ||
| 894 | -使用该接口取消事件订阅后,已通过[emit](#emit22)接口发布但尚未执行的事件将被取消。 | 907 | +使用该接口取消事件订阅后,已通过[emit](#emit22)接口发布但尚未被执行的事件将被取消。 |
| 895 | 908 | ||
| 896 | **原子化服务API:** 从API version 22开始,该接口支持在原子化服务中使用。 | 909 | **原子化服务API:** 从API version 22开始,该接口支持在原子化服务中使用。 |
| 897 | 910 | ||
| 898 | -**系统能力**:`SystemCapability.Notification.Emitter` | 911 | +**系统能力:** SystemCapability.Notification.Emitter |
| 899 | 912 | ||
| 900 | **参数:** | 913 | **参数:** |
| 901 | 914 | ||
| 902 | | 参数名 | 类型 | 必填 | 说明 | | 915 | | 参数名 | 类型 | 必填 | 说明 | |
| 903 | | -------- | ----------------------------------- | ---- | -------------------------- | | 916 | | -------- | ----------------------------------- | ---- | -------------------------- | |
| 904 | -| eventId | string | 是 | 事件ID。取值为长度不超过10240字节的自定义字符串,且不可为空字符。 | | 917 | +| eventId | string | 是 | 事件ID。<br>不可为空字符串,大小不超过10240字节,超出部分会被截断。 | |
| 905 | | callback | Callback\<[EventData](#eventdata)\> | 是 | 回调函数,指定要取消订阅的事件处理函数。 | | 918 | | callback | Callback\<[EventData](#eventdata)\> | 是 | 回调函数,指定要取消订阅的事件处理函数。 | |
| 906 | 919 | ||
| 907 | **示例:** | 920 | **示例:** |
| @@ -913,9 +926,9 @@ let emitter1: emitter.Emitter = new emitter.Emitter(); | |||
| 913 | 926 | ||
| 914 | let callback: Callback<emitter.EventData> = (eventData: emitter.EventData) => { | 927 | let callback: Callback<emitter.EventData> = (eventData: emitter.EventData) => { |
| 915 | console.info(`eventData: ${JSON.stringify(eventData)}`); | 928 | console.info(`eventData: ${JSON.stringify(eventData)}`); |
| 916 | -} | 929 | +}; |
| 917 | 930 | ||
| 918 | -emitter1.off("eventId", callback); | 931 | +emitter1.off('eventId', callback); |
| 919 | ``` | 932 | ``` |
| 920 | 933 | ||
| 921 | ### off<sup>22+</sup> | 934 | ### off<sup>22+</sup> |
| @@ -924,17 +937,17 @@ off<T\>(eventId: string, callback: Callback\<GenericEventData<T\>\>): void | |||
| 924 | 937 | ||
| 925 | 取消订阅当前Emitter类实例的事件。仅当已使用[on](#on22-1)或[once](#once22-1)接口订阅了事件ID为eventId且回调处理函数为callback的事件时,该接口才生效。 | 938 | 取消订阅当前Emitter类实例的事件。仅当已使用[on](#on22-1)或[once](#once22-1)接口订阅了事件ID为eventId且回调处理函数为callback的事件时,该接口才生效。 |
| 926 | 939 | ||
| 927 | -使用该接口取消事件订阅后,已通过[emit](#emit22-1)接口发布但尚未执行的事件将被取消。 | 940 | +使用该接口取消事件订阅后,已通过[emit](#emit22-1)接口发布但尚未被执行的事件将被取消。 |
| 928 | 941 | ||
| 929 | **原子化服务API:** 从API version 22开始,该接口支持在原子化服务中使用。 | 942 | **原子化服务API:** 从API version 22开始,该接口支持在原子化服务中使用。 |
| 930 | 943 | ||
| 931 | -**系统能力**:`SystemCapability.Notification.Emitter` | 944 | +**系统能力:** SystemCapability.Notification.Emitter |
| 932 | 945 | ||
| 933 | **参数:** | 946 | **参数:** |
| 934 | 947 | ||
| 935 | | 参数名 | 类型 | 必填 | 说明 | | 948 | | 参数名 | 类型 | 必填 | 说明 | |
| 936 | | -------- | ----------------------------------- | ---- | -------------------------- | | 949 | | -------- | ----------------------------------- | ---- | -------------------------- | |
| 937 | -| eventId | string | 是 | 事件ID。取值为长度不超过10240字节的自定义字符串,且不可为空字符。 | | 950 | +| eventId | string | 是 | 事件ID。<br>不可为空字符串,大小不超过10240字节,超出部分会被截断。 | |
| 938 | | callback | Callback\<[GenericEventData<T\>](#genericeventdatat12)\> | 是 | 回调函数,指定要取消订阅的事件处理函数。 | | 951 | | callback | Callback\<[GenericEventData<T\>](#genericeventdatat12)\> | 是 | 回调函数,指定要取消订阅的事件处理函数。 | |
| 939 | 952 | ||
| 940 | **示例:** | 953 | **示例:** |
| @@ -960,9 +973,9 @@ let callback: Callback<emitter.GenericEventData<Sample>> = (eventData: emitter.G | |||
| 960 | if (eventData?.data instanceof Sample) { | 973 | if (eventData?.data instanceof Sample) { |
| 961 | eventData?.data?.printCount(); | 974 | eventData?.data?.printCount(); |
| 962 | } | 975 | } |
| 963 | -} | 976 | +}; |
| 964 | 977 | ||
| 965 | -emitter1.off("eventId", callback); | 978 | +emitter1.off('eventId', callback); |
| 966 | ``` | 979 | ``` |
| 967 | 980 | ||
| 968 | ### emit<sup>22+</sup> | 981 | ### emit<sup>22+</sup> |
| @@ -975,15 +988,15 @@ emit(eventId: string, data?: EventData): void | |||
| 975 | 988 | ||
| 976 | 该接口发布某个事件后,不保证该事件立刻执行,执行时间取决于事件队列里面的事件数量以及各事件的执行效率。 | 989 | 该接口发布某个事件后,不保证该事件立刻执行,执行时间取决于事件队列里面的事件数量以及各事件的执行效率。 |
| 977 | 990 | ||
| 978 | -**原子化服务API:** 从API version 22开始支持原子化服务。 | 991 | +**原子化服务API:** 从API version 22开始,该接口支持在原子化服务中使用。 |
| 979 | 992 | ||
| 980 | -**系统能力**:`SystemCapability.Notification.Emitter` | 993 | +**系统能力:** SystemCapability.Notification.Emitter |
| 981 | 994 | ||
| 982 | **参数:** | 995 | **参数:** |
| 983 | 996 | ||
| 984 | | 参数名 | 类型 | 必填 | 说明 | | 997 | | 参数名 | 类型 | 必填 | 说明 | |
| 985 | | ------- | ----------------------- | ---- | ---------------- | | 998 | | ------- | ----------------------- | ---- | ---------------- | |
| 986 | -| eventId | string | 是 | 发送的事件ID。取值为长度不超过10240字节的自定义字符串,且不可为空字符。 | | 999 | +| eventId | string | 是 | 发送的事件ID。<br>不可为空字符串,大小不超过10240字节,超出部分会被截断。 | |
| 987 | | data | [EventData](#eventdata) | 否 | 事件携带的数据,默认为空。| | 1000 | | data | [EventData](#eventdata) | 否 | 事件携带的数据,默认为空。| |
| 988 | 1001 | ||
| 989 | **示例:** | 1002 | **示例:** |
| @@ -992,12 +1005,12 @@ emit(eventId: string, data?: EventData): void | |||
| 992 | let emitter1: emitter.Emitter = new emitter.Emitter(); | 1005 | let emitter1: emitter.Emitter = new emitter.Emitter(); |
| 993 | let eventData: emitter.EventData = { | 1006 | let eventData: emitter.EventData = { |
| 994 | data: { | 1007 | data: { |
| 995 | - "content": "content", | 1008 | + "content": "content", |
| 996 | - "id": 1, | 1009 | + "id": 1, |
| 997 | } | 1010 | } |
| 998 | }; | 1011 | }; |
| 999 | 1012 | ||
| 1000 | -emitter1.emit("eventId", eventData); | 1013 | +emitter1.emit('eventId', eventData); |
| 1001 | ``` | 1014 | ``` |
| 1002 | 1015 | ||
| 1003 | ### emit<sup>22+</sup> | 1016 | ### emit<sup>22+</sup> |
| @@ -1012,13 +1025,13 @@ emit<T\>(eventId: string, data?: GenericEventData<T\>): void | |||
| 1012 | 1025 | ||
| 1013 | **原子化服务API:** 从API version 22开始,该接口支持在原子化服务中使用。 | 1026 | **原子化服务API:** 从API version 22开始,该接口支持在原子化服务中使用。 |
| 1014 | 1027 | ||
| 1015 | -**系统能力**:`SystemCapability.Notification.Emitter` | 1028 | +**系统能力:** SystemCapability.Notification.Emitter |
| 1016 | 1029 | ||
| 1017 | **参数:** | 1030 | **参数:** |
| 1018 | 1031 | ||
| 1019 | | 参数名 | 类型 | 必填 | 说明 | | 1032 | | 参数名 | 类型 | 必填 | 说明 | |
| 1020 | | ------- | ----------------------- | ---- | ---------------- | | 1033 | | ------- | ----------------------- | ---- | ---------------- | |
| 1021 | -| eventId | string | 是 | 发送的事件ID。取值为长度不超过10240字节的自定义字符串,且不可为空字符。 | | 1034 | +| eventId | string | 是 | 发送的事件ID。<br>不可为空字符串,大小不超过10240字节,超出部分会被截断。 | |
| 1022 | | data | [GenericEventData<T\>](#genericeventdatat12) | 否 | 事件携带的数据,默认为空。 | | 1035 | | data | [GenericEventData<T\>](#genericeventdatat12) | 否 | 事件携带的数据,默认为空。 | |
| 1023 | 1036 | ||
| 1024 | **示例:** | 1037 | **示例:** |
| @@ -1041,28 +1054,28 @@ let eventData: emitter.GenericEventData<Sample> = { | |||
| 1041 | data: new Sample() | 1054 | data: new Sample() |
| 1042 | }; | 1055 | }; |
| 1043 | 1056 | ||
| 1044 | -emitter1.emit("eventId", eventData); | 1057 | +emitter1.emit('eventId', eventData); |
| 1045 | ``` | 1058 | ``` |
| 1046 | 1059 | ||
| 1047 | ### emit<sup>22+</sup> | 1060 | ### emit<sup>22+</sup> |
| 1048 | 1061 | ||
| 1049 | emit(eventId: string, options: Options, data?: EventData): void | 1062 | emit(eventId: string, options: Options, data?: EventData): void |
| 1050 | 1063 | ||
| 1051 | -发送指定事件到当前Emitter类实例。 | 1064 | +发送指定优先级事件到当前Emitter类实例。。 |
| 1052 | 1065 | ||
| 1053 | 该接口支持跨线程传输数据对象,需要遵循数据跨线程传输的规格约束,详见[线程间通信对象](../../arkts-utils/serializable-overview.md)。目前不支持使用[@State装饰器](../../ui/state-management/arkts-state.md)、[@Observed装饰器](../../ui/state-management/arkts-observed-and-objectlink.md)等装饰器修饰的复杂类型数据。 | 1066 | 该接口支持跨线程传输数据对象,需要遵循数据跨线程传输的规格约束,详见[线程间通信对象](../../arkts-utils/serializable-overview.md)。目前不支持使用[@State装饰器](../../ui/state-management/arkts-state.md)、[@Observed装饰器](../../ui/state-management/arkts-observed-and-objectlink.md)等装饰器修饰的复杂类型数据。 |
| 1054 | 1067 | ||
| 1055 | 该接口发布某个事件后,不保证该事件立刻执行,执行时间取决于事件队列里面的事件数量以及各事件的执行效率。 | 1068 | 该接口发布某个事件后,不保证该事件立刻执行,执行时间取决于事件队列里面的事件数量以及各事件的执行效率。 |
| 1056 | 1069 | ||
| 1057 | -**原子化服务API:** 从API version 22开始支持原子化服务。 | 1070 | +**原子化服务API:** 从API version 22开始,该接口支持在原子化服务中使用。 |
| 1058 | 1071 | ||
| 1059 | -**系统能力**:`SystemCapability.Notification.Emitter` | 1072 | +**系统能力:** SystemCapability.Notification.Emitter |
| 1060 | 1073 | ||
| 1061 | **参数:** | 1074 | **参数:** |
| 1062 | 1075 | ||
| 1063 | | 参数名 | 类型 | 必填 | 说明 | | 1076 | | 参数名 | 类型 | 必填 | 说明 | |
| 1064 | | ------- | ----------------------- | ---- | ---------------- | | 1077 | | ------- | ----------------------- | ---- | ---------------- | |
| 1065 | -| eventId | string | 是 | 发送的事件ID。取值为长度不超过10240字节的自定义字符串,且不可为空字符。 | | 1078 | +| eventId | string | 是 | 发送的事件ID。<br>不可为空字符串,大小不超过10240字节,超出部分会被截断。 | |
| 1066 | | options | [Options](#options11) | 是 | 事件优先级。 | | 1079 | | options | [Options](#options11) | 是 | 事件优先级。 | |
| 1067 | | data | [EventData](#eventdata) | 否 | 事件携带的数据,默认为空。 | | 1080 | | data | [EventData](#eventdata) | 否 | 事件携带的数据,默认为空。 | |
| 1068 | 1081 | ||
| @@ -1076,12 +1089,12 @@ let options: emitter.Options = { | |||
| 1076 | }; | 1089 | }; |
| 1077 | let eventData: emitter.EventData = { | 1090 | let eventData: emitter.EventData = { |
| 1078 | data: { | 1091 | data: { |
| 1079 | - "content": "content", | 1092 | + "content": "content", |
| 1080 | - "id": 1, | 1093 | + "id": 1, |
| 1081 | } | 1094 | } |
| 1082 | }; | 1095 | }; |
| 1083 | 1096 | ||
| 1084 | -emitter1.emit("eventId", options, eventData); | 1097 | +emitter1.emit('eventId', options, eventData); |
| 1085 | ``` | 1098 | ``` |
| 1086 | 1099 | ||
| 1087 | ### emit<sup>22+</sup> | 1100 | ### emit<sup>22+</sup> |
| @@ -1096,13 +1109,13 @@ emit<T\>(eventId: string, options: Options, data?: GenericEventData<T\>): void | |||
| 1096 | 1109 | ||
| 1097 | **原子化服务API:** 从API version 22开始,该接口支持在原子化服务中使用。 | 1110 | **原子化服务API:** 从API version 22开始,该接口支持在原子化服务中使用。 |
| 1098 | 1111 | ||
| 1099 | -**系统能力**:`SystemCapability.Notification.Emitter` | 1112 | +**系统能力:** SystemCapability.Notification.Emitter |
| 1100 | 1113 | ||
| 1101 | **参数:** | 1114 | **参数:** |
| 1102 | 1115 | ||
| 1103 | | 参数名 | 类型 | 必填 | 说明 | | 1116 | | 参数名 | 类型 | 必填 | 说明 | |
| 1104 | | ------- | ----------------------- | ---- | ---------------- | | 1117 | | ------- | ----------------------- | ---- | ---------------- | |
| 1105 | -| eventId | string | 是 | 发送的事件ID。取值为长度不超过10240字节的自定义字符串,且不可为空字符。 | | 1118 | +| eventId | string | 是 | 发送的事件ID。<br>不可为空字符串,大小不超过10240字节,超出部分会被截断。 | |
| 1106 | | options | [Options](#options11) | 是 | 事件优先级。 | | 1119 | | options | [Options](#options11) | 是 | 事件优先级。 | |
| 1107 | | data | [GenericEventData<T\>](#genericeventdatat12) | 否 | 事件携带的数据,默认为空。 | | 1120 | | data | [GenericEventData<T\>](#genericeventdatat12) | 否 | 事件携带的数据,默认为空。 | |
| 1108 | 1121 | ||
| @@ -1129,7 +1142,7 @@ let eventData: emitter.GenericEventData<Sample> = { | |||
| 1129 | data: new Sample() | 1142 | data: new Sample() |
| 1130 | }; | 1143 | }; |
| 1131 | 1144 | ||
| 1132 | -emitter1.emit("eventId", options, eventData); | 1145 | +emitter1.emit('eventId', options, eventData); |
| 1133 | ``` | 1146 | ``` |
| 1134 | 1147 | ||
| 1135 | ### getListenerCount<sup>22+</sup> | 1148 | ### getListenerCount<sup>22+</sup> |
| @@ -1140,13 +1153,13 @@ getListenerCount(eventId: string): number | |||
| 1140 | 1153 | ||
| 1141 | **原子化服务API:** 从API version 22开始,该接口支持在原子化服务中使用。 | 1154 | **原子化服务API:** 从API version 22开始,该接口支持在原子化服务中使用。 |
| 1142 | 1155 | ||
| 1143 | -**系统能力**:`SystemCapability.Notification.Emitter` | 1156 | +**系统能力:** SystemCapability.Notification.Emitter |
| 1144 | 1157 | ||
| 1145 | **参数:** | 1158 | **参数:** |
| 1146 | 1159 | ||
| 1147 | | 参数名 | 类型 | 必填 | 说明 | | 1160 | | 参数名 | 类型 | 必填 | 说明 | |
| 1148 | | ------- | -------------- | ---- | -------- | | 1161 | | ------- | -------------- | ---- | -------- | |
| 1149 | -| eventId | string | 是 | 事件ID,取值为长度不超过10240字节的自定义字符串,且不可为空字符。 | | 1162 | +| eventId | string | 是 | 事件ID。<br>不可为空字符串,大小不超过10240字节,超出部分会被截断。。 | |
| 1150 | 1163 | ||
| 1151 | **返回值:** | 1164 | **返回值:** |
| 1152 | 1165 | ||
| @@ -1159,5 +1172,5 @@ getListenerCount(eventId: string): number | |||
| 1159 | 1172 | ||
| 1160 | ```ts | 1173 | ```ts |
| 1161 | let emitter1: emitter.Emitter = new emitter.Emitter(); | 1174 | let emitter1: emitter.Emitter = new emitter.Emitter(); |
| 1162 | -let count = emitter1.getListenerCount("eventId"); | 1175 | +let count: number = emitter1.getListenerCount('eventId'); |
| 1163 | -``` | 1176 | +``` |
Mzh-cn/application-dev/reference/apis-basic-services-kit/js-apis-inner-commonEvent-commonEventData.md+5-5
| @@ -6,7 +6,7 @@ | |||
| 6 | <!--Tester: @wanghong1997--> | 6 | <!--Tester: @wanghong1997--> |
| 7 | <!--Adviser: @fang-jinxu--> | 7 | <!--Adviser: @fang-jinxu--> |
| 8 | 8 | ||
| 9 | -表示公共事件的数据。 | 9 | +表示公共事件的数据。CommonEventData用于在公共事件订阅场景中承载订阅者接收到的公共事件数据,包含事件名称、发布者包名、code数据、data数据及附加参数等信息,适用于应用订阅并处理公共事件、解析事件携带数据的场景。 |
| 10 | 10 | ||
| 11 | > **说明:** | 11 | > **说明:** |
| 12 | > | 12 | > |
| @@ -21,7 +21,7 @@ | |||
| 21 | | 名称 | 类型 | 只读 | 可选 | 说明 | | 21 | | 名称 | 类型 | 只读 | 可选 | 说明 | |
| 22 | | ---------- |-------------------- | ---- | ---- | ------------------------------------------------------- | | 22 | | ---------- |-------------------- | ---- | ---- | ------------------------------------------------------- | |
| 23 | | event | string | 否 | 否 | 表示当前接收的公共事件名称。 | | 23 | | event | string | 否 | 否 | 表示当前接收的公共事件名称。 | |
| 24 | -| bundleName | string | 否 | 是 | 表示包名称,默认为空字符串。 | | 24 | +| bundleName | string | 否 | 是 | 表示发布公共事件的应用包名,默认为空字符串。 | |
| 25 | -| code | number | 否 | 是 | 表示订阅者接收到的公共事件数据(number类型)。该字段取值与发布者使用[commonEventManager.publish](./js-apis-commonEventManager.md#commoneventmanagerpublish-1)发布公共事件时,通过[CommonEventPublishData](./js-apis-inner-commonEvent-commonEventPublishData.md)中的`code`字段传递的数据一致。默认值为0。 | | 25 | +| code | number | 否 | 是 | 表示订阅者接收到的公共事件数据(number类型)。该字段取值与发布者使用[commonEventManager.publish](./js-apis-commonEventManager.md#commoneventmanagerpublish-1)发布公共事件时,通过[CommonEventPublishData](./js-apis-inner-commonEvent-commonEventPublishData.md)中的`code`字段传递的数据一致。取值范围[-2147483648, 2147483647],默认值为0。 | |
| 26 | -| data | string | 否 | 是 | 表示订阅者接收到的公共事件数据(string类型)。该字段取值与发布者使用[commonEventManager.publish](./js-apis-commonEventManager.md#commoneventmanagerpublish-1)发布公共事件时,通过[CommonEventPublishData](./js-apis-inner-commonEvent-commonEventPublishData.md)中的`data`字段传递的数据一致。 | | 26 | +| data | string | 否 | 是 | 表示订阅者接收到的公共事件数据(string类型),数据大小不超过64KB。该字段取值与发布者使用[commonEventManager.publish](./js-apis-commonEventManager.md#commoneventmanagerpublish-1)发布公共事件时,通过[CommonEventPublishData](./js-apis-inner-commonEvent-commonEventPublishData.md)中的`data`字段传递的数据一致。 | |
| 27 | -| parameters | {[key: string]: any} | 否 | 是 | 表示订阅者接收到的公共事件的附加信息。该字段取值与发布者使用[commonEventManager.publish](./js-apis-commonEventManager.md#commoneventmanagerpublish-1)发布公共事件时,通过[CommonEventPublishData](./js-apis-inner-commonEvent-commonEventPublishData.md)中的`parameters`字段传递的数据一致。 | | 27 | +| parameters | {[key: string]: any} | 否 | 是 | 表示订阅者接收到的公共事件的附加信息。该字段取值与发布者使用[commonEventManager.publish](./js-apis-commonEventManager.md#commoneventmanagerpublish-1)发布公共事件时,通过[CommonEventPublishData](./js-apis-inner-commonEvent-commonEventPublishData.md)中的`parameters`字段传递的数据一致。 | |
| @@ -6,13 +6,13 @@ | |||
| 6 | <!--Tester: @wanghong1997--> | 6 | <!--Tester: @wanghong1997--> |
| 7 | <!--Adviser: @fang-jinxu--> | 7 | <!--Adviser: @fang-jinxu--> |
| 8 | 8 | ||
| 9 | -包含公共事件内容和属性。 | 9 | +用于封装公共事件发布时携带的数据和属性,包括事件数据(code/data)、订阅者权限、订阅者包名、是否有序/粘性事件及附加参数等,支持发布方对公共事件接收方范围、事件投递顺序及粘性特性进行精细化控制,适用于需要限定接收方、传递自定义事件数据或实现有序/粘性公共事件等场景。 |
| 10 | 10 | ||
| 11 | > **说明:** | 11 | > **说明:** |
| 12 | > | 12 | > |
| 13 | > 本模块首批接口从API version 7开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 | 13 | > 本模块首批接口从API version 7开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 |
| 14 | > | 14 | > |
| 15 | -> 如果不加限制,任何应用都可以订阅公共事件并读取相关信息,应避免在公共事件中携带敏感信息。通过本模块的subscriberPermissions和bundleName参数,可以限制公共事件接收方的范围。 | 15 | +> 如果不加限制,任何应用都可以订阅公共事件并读取公共事件携带的信息,应避免在公共事件中携带敏感信息。通过本模块的subscriberPermissions和bundleName参数,可以限制公共事件接收方的范围。 |
| 16 | 16 | ||
| 17 | ## 属性 | 17 | ## 属性 |
| 18 | 18 | ||
| @@ -20,10 +20,10 @@ | |||
| 20 | 20 | ||
| 21 | | 名称 | 类型 | 只读 | 可选 | 说明 | | 21 | | 名称 | 类型 | 只读 | 可选 | 说明 | |
| 22 | | --------------------- | -------------------- | ---- | ---- | ---------------------------- | | 22 | | --------------------- | -------------------- | ---- | ---- | ---------------------------- | |
| 23 | -| bundleName | string | 否 | 是 | 表示订阅者包名称,只有包名为bundleName的订阅者才能收到该公共事件。<br>**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 | | 23 | +| bundleName | string | 否 | 是 | 表示订阅者包名,用于限定将公共事件发布给指定包名的订阅者。<br>**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 | |
| 24 | | code | number | 否 | 是 | 表示发布方传递的公共事件数据(number类型)。默认值为0。<br>**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 | | 24 | | code | number | 否 | 是 | 表示发布方传递的公共事件数据(number类型)。默认值为0。<br>**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 | |
| 25 | | data | string | 否 | 是 | 表示发布方传递的公共事件数据(string类型)。数据大小不超过64KB。<br>**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 | | 25 | | data | string | 否 | 是 | 表示发布方传递的公共事件数据(string类型)。数据大小不超过64KB。<br>**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 | |
| 26 | -| subscriberPermissions | Array\<string> | 否 | 是 | 表示订阅者的权限。<br>**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 | | 26 | +| subscriberPermissions | Array\<string> | 否 | 是 | 表示订阅者的权限,只有具备该权限的订阅者才能收到该公共事件。<br>**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 | |
| 27 | -| isOrdered | boolean | 否 | 是 | 表示是否是有序事件。默认为false。<br/> - true:有序公共事件,根据订阅者设置的优先级等级,优先将公共事件发送给优先级较高的订阅者,等待其成功接收该公共事件之后再将事件发送给优先级较低的订阅者。如果有多个订阅者具有相同的优先级,则他们将随机接收到公共事件。<br/> - false:无序公共事件,不考虑订阅者是否接收到该事件,也不保证订阅者接收到该事件的顺序与其订阅顺序一致。 | | 27 | +| isOrdered | boolean | 否 | 是 | 表示是否是有序公共事件。默认为false。<br> - true:有序公共事件,根据订阅者设置的优先级等级,优先将公共事件发送给优先级较高的订阅者,等待其成功接收该公共事件之后再将事件发送给优先级较低的订阅者。如果有多个订阅者具有相同的优先级,则他们将随机接收到公共事件。<br> - false:无序公共事件,不考虑订阅者是否接收到该事件,也不保证订阅者接收到该事件的顺序与其订阅顺序一致。 | |
| 28 | -| isSticky | boolean | 否 | 是 | 表示是否是粘性事件。默认为false。<br/> - true:粘性公共事件,能够让订阅者收到在订阅前已经发送的公共事件。<br/> - false:普通公共事件,只能让订阅者收到在订阅后才发送的公共事件。<br>仅系统应用或系统服务允许发送粘性事件。<br>**需要权限**:[ohos.permission.COMMONEVENT_STICKY](../../security/AccessToken/permissions-for-all.md#ohospermissioncommonevent_sticky) | | 28 | +| isSticky | boolean | 否 | 是 | 表示是否是粘性公共事件。默认为false。<br> - true:粘性公共事件,能够让订阅者收到在订阅前已经发送的公共事件。<br> - false:普通公共事件,只能让订阅者收到在订阅后才发送的公共事件。<br>仅系统应用或系统服务允许发送粘性事件。<br>**需要权限:**[ohos.permission.COMMONEVENT_STICKY](../../security/AccessToken/permissions-for-all.md#ohospermissioncommonevent_sticky) | |
| 29 | -| parameters | {[key: string]: any} | 否 | 是 | 表示发布方传递的公共事件的附加信息。<br>**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 | | 29 | +| parameters | {[key: string]: any} | 否 | 是 | 表示发布方传递的公共事件的附加信息,以键值对形式携带自定义参数。<br>**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 | |
| @@ -6,13 +6,13 @@ | |||
| 6 | <!--Tester: @wanghong1997--> | 6 | <!--Tester: @wanghong1997--> |
| 7 | <!--Adviser: @fang-jinxu--> | 7 | <!--Adviser: @fang-jinxu--> |
| 8 | 8 | ||
| 9 | -用于表示订阅者的信息。 | 9 | +用于表示公共事件订阅者的信息,支持配置订阅的公共事件类型、发布者权限、发布者设备ID、用户ID、订阅优先级等参数,适用于应用需要订阅系统公共事件或自定义公共事件并精细化控制事件来源的场景。 |
| 10 | 10 | ||
| 11 | > **说明:** | 11 | > **说明:** |
| 12 | > | 12 | > |
| 13 | > 本模块首批接口从API version 7开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 | 13 | > 本模块首批接口从API version 7开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 |
| 14 | > | 14 | > |
| 15 | -> 订阅自定义公共事件后,任意应用都可以向订阅者发送潜在的恶意公共事件。通过本模块的publisherPermission和publisherBundleName参数,可以限制公共事件发布方的范围。 | 15 | +> 订阅自定义公共事件后,任意应用都可以向订阅者发送潜在的恶意公共事件。通过本模块的publisherPermission和publisherBundleName参数,可以限制公共事件发布者的范围。 |
| 16 | 16 | ||
| 17 | ## 属性 | 17 | ## 属性 |
| 18 | 18 | ||
| @@ -22,9 +22,9 @@ | |||
| 22 | 22 | ||
| 23 | | 名称 | 类型 | 只读 | 可选 | 说明 | | 23 | | 名称 | 类型 | 只读 | 可选 | 说明 | |
| 24 | | ------------------- | -------------- | ---- | ---- | ------------------------------------------------------------ | | 24 | | ------------------- | -------------- | ---- | ---- | ------------------------------------------------------------ | |
| 25 | -| events | Array\<string> | 否 | 否 | 表示要订阅的公共事件。 | | 25 | +| events | Array\<string> | 否 | 否 | 表示要订阅的公共事件列表。 | |
| 26 | -| publisherPermission | string | 否 | 是 | 表示发布者的权限,订阅方将只能接收到具有该权限的发送方发布的事件。 | | 26 | +| publisherPermission | string | 否 | 是 | 表示发布者的权限,取值为系统已定义的权限名,订阅方将只能接收到具有该权限的发送方发布的事件。不设置时,可接收所有发送方发布的事件。 | |
| 27 | -| publisherDeviceId | string | 否 | 是 | 表示设备ID。通过[@ohos.deviceInfo](js-apis-device-info.md)获取udid,作为订阅者的设备ID。预留能力,暂不支持。 | | 27 | +| publisherDeviceId | string | 否 | 是 | 表示设备ID,用于限制订阅者只接收来自指定设备发布的公共事件。通过[@ohos.deviceInfo](js-apis-device-info.md)获取udid,作为发布者的设备ID。预留能力,暂不支持。 | |
| 28 | -| userId | number | 否 | 是 | 表示用户ID。此参数是可选的,默认值当前用户的ID。如果指定了此参数,则该值必须是系统中现有的用户ID。通过[getOsAccountLocalId](./js-apis-osAccount.md#getosaccountlocalid9)获取系统账号ID,作为订阅者的用户ID。 | | 28 | +| userId | number | 否 | 是 | 表示用户ID,用于限制订阅者只接收指定用户ID相关的公共事件。此参数是可选的,默认值为当前用户的ID。如果指定了此参数,则该值必须是系统中现有的用户ID。通过[getOsAccountLocalId](./js-apis-osAccount.md#getosaccountlocalid9)获取系统用户ID,作为发布者的用户ID。 | |
| 29 | -| priority | number | 否 | 是 | 表示订阅者的优先级。值的范围是-100到1000,超过上下限的优先级将被设置为上下限值。 | | 29 | +| priority | number | 否 | 是 | 表示订阅者的优先级,优先级越高的订阅者,越优先接收到有序公共事件。取值范围是-100到1000,超过上下限的优先级将被设置为对应的上下限值,默认优先级为0。 | |
| 30 | -| publisherBundleName<sup>11+</sup> | string | 否 | 是 | 表示要订阅的发布者的bundleName。 | | 30 | +| publisherBundleName<sup>11+</sup> | string | 否 | 是 | 表示要订阅的发布者的bundleName,用于限制订阅方只接收该bundleName的发布者发布的公共事件。不设置时,可接收所有应用发布的公共事件。 | |
| @@ -12,7 +12,7 @@ | |||
| 12 | 12 | ||
| 13 | ## CommonEventSubscriber | 13 | ## CommonEventSubscriber |
| 14 | 14 | ||
| 15 | -表示公共事件的订阅者。 | 15 | +表示公共事件的订阅者。CommonEventSubscriber提供了对有序公共事件的处理能力,包括获取和设置事件传递的Code和Data数据、查询当前公共事件是否为有序或粘性事件、中止或清理有序公共事件的中止状态、结束对当前有序公共事件的处理,以及获取订阅者的订阅信息等,适用于订阅者需要对接收到的公共事件进行数据处理和流程控制的场景。 |
| 16 | 16 | ||
| 17 | **原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 | 17 | **原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 |
| 18 | 18 | ||
| @@ -20,7 +20,7 @@ | |||
| 20 | 20 | ||
| 21 | ### 使用说明 | 21 | ### 使用说明 |
| 22 | 22 | ||
| 23 | -在使用CommonEventSubscriber的功能前,需要通过[commonEventManager.createSubscriber](js-apis-commonEventManager.md#commoneventmanagercreatesubscriber-1)获取subscriber对象。 | 23 | +在使用CommonEventSubscriber的功能前,需要通过[commonEventManager.createSubscriberSync](js-apis-commonEventManager.md#commoneventmanagercreatesubscribersync10)获取subscriber对象。 |
| 24 | 24 | ||
| 25 | <!--code_no_check--> | 25 | <!--code_no_check--> |
| 26 | ```ts | 26 | ```ts |
| @@ -45,13 +45,13 @@ getCode(callback: AsyncCallback\<number>): void | |||
| 45 | 45 | ||
| 46 | **原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 | 46 | **原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 |
| 47 | 47 | ||
| 48 | -**系统能力:** `SystemCapability.Notification.CommonEvent` | 48 | +**系统能力:** SystemCapability.Notification.CommonEvent |
Z | |||
| 49 | 49 | ||
| 50 | **参数:** | 50 | **参数:** |
| 51 | 51 | ||
| 52 | | 参数名 | 类型 | 必填 | 说明 | | 52 | | 参数名 | 类型 | 必填 | 说明 | |
| 53 | | -------- | ---------------------- | ---- | ------------------ | | 53 | | -------- | ---------------------- | ---- | ------------------ | |
| 54 | -| callback | AsyncCallback\<number\> | 是 | 回调函数。返回有序公共事件传递的数据(number类型)。 | | 54 | +| callback | AsyncCallback\<number\> | 是 | 回调函数。当获取有序公共事件传递的数据(number类型)成功时,err为undefined,data为获取到的数据;否则err为错误对象。 | |
| 55 | 55 | ||
| 56 | **错误码:** | 56 | **错误码:** |
| 57 | 57 | ||
| @@ -68,7 +68,7 @@ getCode(callback: AsyncCallback\<number>): void | |||
| 68 | ```ts | 68 | ```ts |
| 69 | subscriber.getCode((err: BusinessError, code: number) => { | 69 | subscriber.getCode((err: BusinessError, code: number) => { |
| 70 | if (err) { | 70 | if (err) { |
| 71 | - console.error(`Failed to get code. Code is ${err.code}, message is ${err.message}`); | 71 | + console.error(`Failed to get code. Code: ${err.code}, message: ${err.message}`); |
| 72 | return; | 72 | return; |
| 73 | } | 73 | } |
| 74 | console.info(`Succeeded in getting code, code is ${JSON.stringify(code)}`); | 74 | console.info(`Succeeded in getting code, code is ${JSON.stringify(code)}`); |
| @@ -83,7 +83,7 @@ getCode(): Promise\<number> | |||
| 83 | 83 | ||
| 84 | **原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 | 84 | **原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 |
| 85 | 85 | ||
| 86 | -**系统能力:** `SystemCapability.Notification.CommonEvent` | 86 | +**系统能力:** SystemCapability.Notification.CommonEvent |
| 87 | 87 | ||
| 88 | **返回值:** | 88 | **返回值:** |
| 89 | 89 | ||
| @@ -107,17 +107,17 @@ subscriber.getCode().then((code: number) => { | |||
| 107 | 107 | ||
| 108 | getCodeSync(): number | 108 | getCodeSync(): number |
| 109 | 109 | ||
| 110 | -获取有序公共事件传递的数据(number类型)。 | 110 | +同步获取有序公共事件传递的数据(number类型)。 |
| 111 | 111 | ||
| 112 | **原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 | 112 | **原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 |
| 113 | 113 | ||
| 114 | -**系统能力:** `SystemCapability.Notification.CommonEvent` | 114 | +**系统能力:** SystemCapability.Notification.CommonEvent |
| 115 | 115 | ||
| 116 | **返回值:** | 116 | **返回值:** |
| 117 | 117 | ||
| 118 | | 类型 | 说明 | | 118 | | 类型 | 说明 | |
| 119 | | ---------------- | -------------------- | | 119 | | ---------------- | -------------------- | |
| 120 | -| number | 表示有序公共事件传递的数据(number类型)。 | | 120 | +| number | 有序公共事件传递的数据(number类型)。 | |
| 121 | 121 | ||
| 122 | **示例:** | 122 | **示例:** |
| 123 | 123 | ||
| @@ -136,7 +136,7 @@ setCode(code: number, callback: AsyncCallback\<void>): void | |||
| 136 | 136 | ||
| 137 | **原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 | 137 | **原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 |
| 138 | 138 | ||
| 139 | -**系统能力:** `SystemCapability.Notification.CommonEvent` | 139 | +**系统能力:** SystemCapability.Notification.CommonEvent |
| 140 | 140 | ||
| 141 | **参数:** | 141 | **参数:** |
| 142 | 142 | ||
| @@ -175,7 +175,7 @@ setCode(code: number): Promise\<void> | |||
| 175 | 175 | ||
| 176 | **原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 | 176 | **原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 |
| 177 | 177 | ||
| 178 | -**系统能力:** `SystemCapability.Notification.CommonEvent` | 178 | +**系统能力:** SystemCapability.Notification.CommonEvent |
| 179 | 179 | ||
| 180 | **参数:** | 180 | **参数:** |
| 181 | 181 | ||
| @@ -217,7 +217,7 @@ setCodeSync(code: number): void | |||
| 217 | 217 | ||
| 218 | **原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 | 218 | **原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 |
| 219 | 219 | ||
| 220 | -**系统能力:** `SystemCapability.Notification.CommonEvent` | 220 | +**系统能力:** SystemCapability.Notification.CommonEvent |
| 221 | 221 | ||
| 222 | **参数:** | 222 | **参数:** |
| 223 | 223 | ||
| @@ -254,13 +254,13 @@ getData(callback: AsyncCallback\<string>): void | |||
| 254 | 254 | ||
| 255 | **原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 | 255 | **原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 |
| 256 | 256 | ||
| 257 | -**系统能力:** `SystemCapability.Notification.CommonEvent` | 257 | +**系统能力:** SystemCapability.Notification.CommonEvent |
| 258 | 258 | ||
| 259 | **参数:** | 259 | **参数:** |
| 260 | 260 | ||
| 261 | | 参数名 | 类型 | 必填 | 说明 | | 261 | | 参数名 | 类型 | 必填 | 说明 | |
| 262 | | -------- | ---------------------- | ---- | -------------------- | | 262 | | -------- | ---------------------- | ---- | -------------------- | |
| 263 | -| callback | AsyncCallback\<string> | 是 | 回调函数。返回有序公共事件传递的数据(string类型)。 | | 263 | +| callback | AsyncCallback\<string> | 是 | 回调函数。当获取有序公共事件传递的数据(string类型)成功时,err为undefined,data为获取到的数据;否则err为错误对象。 | |
| 264 | 264 | ||
| 265 | **错误码:** | 265 | **错误码:** |
| 266 | 266 | ||
| @@ -293,7 +293,7 @@ getData(): Promise\<string> | |||
| 293 | 293 | ||
| 294 | **原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 | 294 | **原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 |
| 295 | 295 | ||
| 296 | -**系统能力:** `SystemCapability.Notification.CommonEvent` | 296 | +**系统能力:** SystemCapability.Notification.CommonEvent |
| 297 | 297 | ||
| 298 | **返回值:** | 298 | **返回值:** |
| 299 | 299 | ||
| @@ -321,7 +321,7 @@ getDataSync(): string | |||
| 321 | 321 | ||
| 322 | **原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 | 322 | **原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 |
| 323 | 323 | ||
| 324 | -**系统能力:** `SystemCapability.Notification.CommonEvent` | 324 | +**系统能力:** SystemCapability.Notification.CommonEvent |
| 325 | 325 | ||
| 326 | **返回值:** | 326 | **返回值:** |
| 327 | 327 | ||
| @@ -346,13 +346,13 @@ setData(data: string, callback: AsyncCallback\<void>): void | |||
| 346 | 346 | ||
| 347 | **原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 | 347 | **原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 |
| 348 | 348 | ||
| 349 | -**系统能力:** `SystemCapability.Notification.CommonEvent` | 349 | +**系统能力:** SystemCapability.Notification.CommonEvent |
| 350 | 350 | ||
| 351 | **参数:** | 351 | **参数:** |
| 352 | 352 | ||
| 353 | | 参数名 | 类型 | 必填 | 说明 | | 353 | | 参数名 | 类型 | 必填 | 说明 | |
| 354 | | -------- | -------------------- | ---- | -------------------- | | 354 | | -------- | -------------------- | ---- | -------------------- | |
| 355 | -| data | string | 是 | 有序公共事件传递的数据(string类型)。 | | 355 | +| data | string | 是 | 有序公共事件传递的数据(string类型),长度不超过65536字符,若超过限制,接口设置失效。 | |
| 356 | | callback | AsyncCallback\<void> | 是 | 回调函数。当设置有序公共事件传递的数据(string类型)成功时,err为undefined,否则为错误对象。 | | 356 | | callback | AsyncCallback\<void> | 是 | 回调函数。当设置有序公共事件传递的数据(string类型)成功时,err为undefined,否则为错误对象。 | |
| 357 | 357 | ||
| 358 | **错误码:** | 358 | **错误码:** |
| @@ -385,7 +385,7 @@ setData(data: string): Promise\<void> | |||
| 385 | 385 | ||
| 386 | **原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 | 386 | **原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 |
| 387 | 387 | ||
| 388 | -**系统能力:** `SystemCapability.Notification.CommonEvent` | 388 | +**系统能力:** SystemCapability.Notification.CommonEvent |
| 389 | 389 | ||
| 390 | **参数:** | 390 | **参数:** |
| 391 | 391 | ||
| @@ -427,13 +427,13 @@ setDataSync(data: string): void | |||
| 427 | 427 | ||
| 428 | **原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 | 428 | **原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 |
| 429 | 429 | ||
| 430 | -**系统能力:** `SystemCapability.Notification.CommonEvent` | 430 | +**系统能力:** SystemCapability.Notification.CommonEvent |
| 431 | 431 | ||
| 432 | **参数:** | 432 | **参数:** |
| 433 | 433 | ||
| 434 | | 参数名 | 类型 | 必填 | 说明 | | 434 | | 参数名 | 类型 | 必填 | 说明 | |
| 435 | | ------ | ------ | ---- | -------------------- | | 435 | | ------ | ------ | ---- | -------------------- | |
| 436 | -| data | string | 是 | 有序公共事件传递的数据(string类型)。 | | 436 | +| data | string | 是 | 有序公共事件传递的数据(string类型),长度不超过65536字符,若超过限制,接口设置失效。 | |
| 437 | 437 | ||
| 438 | **错误码:** | 438 | **错误码:** |
| 439 | 439 | ||
| @@ -458,20 +458,20 @@ try { | |||
| 458 | 458 | ||
| 459 | ### setCodeAndData | 459 | ### setCodeAndData |
| 460 | 460 | ||
| 461 | -setCodeAndData(code: number, data: string, callback:AsyncCallback\<void>): void | 461 | +setCodeAndData(code: number, data: string, callback: AsyncCallback\<void\>): void |
| 462 | 462 | ||
| 463 | -设置有序公共事件数据。使用callback异步回调。 | 463 | +设置有序公共事件传递的数据。使用callback异步回调。 |
| 464 | 464 | ||
| 465 | **原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 | 465 | **原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 |
| 466 | 466 | ||
| 467 | -**系统能力:** `SystemCapability.Notification.CommonEvent` | 467 | +**系统能力:** SystemCapability.Notification.CommonEvent |
| 468 | 468 | ||
| 469 | **参数:** | 469 | **参数:** |
| 470 | 470 | ||
| 471 | | 参数名 | 类型 | 必填 | 说明 | | 471 | | 参数名 | 类型 | 必填 | 说明 | |
| 472 | | -------- | -------------------- | ---- | ---------------------- | | 472 | | -------- | -------------------- | ---- | ---------------------- | |
| 473 | | code | number | 是 | 有序公共事件传递的数据(number类型)。 | | 473 | | code | number | 是 | 有序公共事件传递的数据(number类型)。 | |
| 474 | -| data | string | 是 | 有序公共事件传递的数据(string类型)。 | | 474 | +| data | string | 是 | 有序公共事件传递的数据(string类型),长度不超过65536字符,若超过限制,接口设置失效。 | |
| 475 | | callback | AsyncCallback\<void> | 是 | 回调函数。当设置有序公共事件传递的数据成功时,err为undefined,否则为错误对象。 | | 475 | | callback | AsyncCallback\<void> | 是 | 回调函数。当设置有序公共事件传递的数据成功时,err为undefined,否则为错误对象。 | |
| 476 | 476 | ||
| 477 | **错误码:** | 477 | **错误码:** |
| @@ -504,14 +504,14 @@ setCodeAndData(code: number, data: string): Promise\<void> | |||
| 504 | 504 | ||
| 505 | **原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 | 505 | **原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 |
| 506 | 506 | ||
| 507 | -**系统能力:** `SystemCapability.Notification.CommonEvent` | 507 | +**系统能力:** SystemCapability.Notification.CommonEvent |
| 508 | 508 | ||
| 509 | **参数:** | 509 | **参数:** |
| 510 | 510 | ||
| 511 | | 参数名 | 类型 | 必填 | 说明 | | 511 | | 参数名 | 类型 | 必填 | 说明 | |
| 512 | | ------ | ------ | ---- | -------------------- | | 512 | | ------ | ------ | ---- | -------------------- | |
| 513 | | code | number | 是 | 有序公共事件传递的数据(number类型)。 | | 513 | | code | number | 是 | 有序公共事件传递的数据(number类型)。 | |
| 514 | -| data | string | 是 | 有序公共事件传递的数据(string类型)。 | | 514 | +| data | string | 是 | 有序公共事件传递的数据(string类型),长度不超过65536字符,若超过限制,接口设置失效。 | |
| 515 | 515 | ||
| 516 | **返回值:** | 516 | **返回值:** |
| 517 | 517 | ||
| @@ -547,14 +547,14 @@ setCodeAndDataSync(code: number, data: string): void | |||
| 547 | 547 | ||
| 548 | **原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 | 548 | **原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 |
| 549 | 549 | ||
| 550 | -**系统能力:** `SystemCapability.Notification.CommonEvent` | 550 | +**系统能力:** SystemCapability.Notification.CommonEvent |
| 551 | 551 | ||
| 552 | **参数:** | 552 | **参数:** |
| 553 | 553 | ||
| 554 | | 参数名 | 类型 | 必填 | 说明 | | 554 | | 参数名 | 类型 | 必填 | 说明 | |
| 555 | | ------ | ------ | ---- | -------------------- | | 555 | | ------ | ------ | ---- | -------------------- | |
| 556 | | code | number | 是 | 有序公共事件传递的数据(number类型)。 | | 556 | | code | number | 是 | 有序公共事件传递的数据(number类型)。 | |
| 557 | -| data | string | 是 | 有序公共事件传递的数据(string类型)。 | | 557 | +| data | string | 是 | 有序公共事件传递的数据(string类型),长度不超过65536字符,若超过限制,接口设置失效。 | |
| 558 | 558 | ||
| 559 | **错误码:** | 559 | **错误码:** |
| 560 | 560 | ||
| @@ -584,13 +584,13 @@ isOrderedCommonEvent(callback: AsyncCallback\<boolean>): void | |||
| 584 | 584 | ||
| 585 | 查询当前公共事件是否为有序公共事件。使用callback异步回调。 | 585 | 查询当前公共事件是否为有序公共事件。使用callback异步回调。 |
| 586 | 586 | ||
| 587 | -**系统能力:** `SystemCapability.Notification.CommonEvent` | 587 | +**系统能力:** SystemCapability.Notification.CommonEvent |
| 588 | 588 | ||
| 589 | **参数:** | 589 | **参数:** |
| 590 | 590 | ||
| 591 | | 参数名 | 类型 | 必填 | 说明 | | 591 | | 参数名 | 类型 | 必填 | 说明 | |
| 592 | | -------- | ----------------------- | ---- | ---------------------------------- | | 592 | | -------- | ----------------------- | ---- | ---------------------------------- | |
| 593 | -| callback | AsyncCallback\<boolean> | 是 | 回调函数。返回true表示有序公共事件;返回false表示无序公共事件。 | | 593 | +| callback | AsyncCallback\<boolean> | 是 | 回调函数。当查询成功时,err为undefined,data为true表示有序公共事件,data为false表示不是有序公共事件;否则err为错误对象。 | |
| 594 | 594 | ||
| 595 | **错误码:** | 595 | **错误码:** |
| 596 | 596 | ||
| @@ -605,9 +605,9 @@ isOrderedCommonEvent(callback: AsyncCallback\<boolean>): void | |||
| 605 | <!--code_no_check--> | 605 | <!--code_no_check--> |
| 606 | 606 | ||
| 607 | ```ts | 607 | ```ts |
| 608 | -subscriber.isOrderedCommonEvent((err: BusinessError, isOrdered:boolean) => { | 608 | +subscriber.isOrderedCommonEvent((err: BusinessError, isOrdered: boolean) => { |
| 609 | if (err) { | 609 | if (err) { |
| 610 | - console.error(`isOrderedCommonEvent failed, code is ${err.code}, message is ${err.message}`); | 610 | + console.error(`Failed to check ordered common event. Code: ${err.code}, message: ${err.message}`); |
| 611 | return; | 611 | return; |
| 612 | } | 612 | } |
| 613 | console.info(`isOrderedCommonEvent ${JSON.stringify(isOrdered)}`); | 613 | console.info(`isOrderedCommonEvent ${JSON.stringify(isOrdered)}`); |
| @@ -620,7 +620,7 @@ isOrderedCommonEvent(): Promise\<boolean> | |||
| 620 | 620 | ||
| 621 | 查询当前公共事件是否为有序公共事件。使用Promise异步回调。 | 621 | 查询当前公共事件是否为有序公共事件。使用Promise异步回调。 |
| 622 | 622 | ||
| 623 | -**系统能力:** `SystemCapability.Notification.CommonEvent` | 623 | +**系统能力:** SystemCapability.Notification.CommonEvent |
| 624 | 624 | ||
| 625 | **返回值:** | 625 | **返回值:** |
| 626 | 626 | ||
| @@ -633,7 +633,7 @@ isOrderedCommonEvent(): Promise\<boolean> | |||
| 633 | <!--code_no_check--> | 633 | <!--code_no_check--> |
| 634 | 634 | ||
| 635 | ```ts | 635 | ```ts |
| 636 | -subscriber.isOrderedCommonEvent().then((isOrdered:boolean) => { | 636 | +subscriber.isOrderedCommonEvent().then((isOrdered: boolean) => { |
| 637 | console.info(`isOrderedCommonEvent ${JSON.stringify(isOrdered)}`); | 637 | console.info(`isOrderedCommonEvent ${JSON.stringify(isOrdered)}`); |
| 638 | }).catch((err: BusinessError) => { | 638 | }).catch((err: BusinessError) => { |
| 639 | console.error(`isOrderedCommonEvent failed, code is ${err.code}, message is ${err.message}`); | 639 | console.error(`isOrderedCommonEvent failed, code is ${err.code}, message is ${err.message}`); |
| @@ -646,13 +646,13 @@ isOrderedCommonEventSync(): boolean | |||
| 646 | 646 | ||
| 647 | 查询当前公共事件是否为有序公共事件。 | 647 | 查询当前公共事件是否为有序公共事件。 |
| 648 | 648 | ||
| 649 | -**系统能力:** `SystemCapability.Notification.CommonEvent` | 649 | +**系统能力:** SystemCapability.Notification.CommonEvent |
| 650 | 650 | ||
| 651 | **返回值:** | 651 | **返回值:** |
| 652 | 652 | ||
| 653 | | 类型 | 说明 | | 653 | | 类型 | 说明 | |
| 654 | | ----------------- | -------------------------------- | | 654 | | ----------------- | -------------------------------- | |
| 655 | -| boolean |返回true表示有序公共事件;返回false表示无序公共事件。 | | 655 | +| boolean | 返回true表示有序公共事件;返回false表示无序公共事件。 | |
| 656 | 656 | ||
| 657 | **示例:** | 657 | **示例:** |
| 658 | 658 | ||
| @@ -667,15 +667,15 @@ console.info(`isOrderedCommonEventSync ${JSON.stringify(isOrdered)}`); | |||
| 667 | 667 | ||
| 668 | isStickyCommonEvent(callback: AsyncCallback\<boolean>): void | 668 | isStickyCommonEvent(callback: AsyncCallback\<boolean>): void |
| 669 | 669 | ||
| 670 | -检查当前公共事件是否为一个粘性事件。使用callback异步回调。 | 670 | +查询当前公共事件是否为一个粘性公共事件。使用callback异步回调。 |
| 671 | 671 | ||
| 672 | -**系统能力:** `SystemCapability.Notification.CommonEvent` | 672 | +**系统能力:** SystemCapability.Notification.CommonEvent |
| 673 | 673 | ||
| 674 | **参数:** | 674 | **参数:** |
| 675 | 675 | ||
| 676 | | 参数名 | 类型 | 必填 | 说明 | | 676 | | 参数名 | 类型 | 必填 | 说明 | |
| 677 | | -------- | ----------------------- | ---- | ---------------------------------- | | 677 | | -------- | ----------------------- | ---- | ---------------------------------- | |
| 678 | -| callback | AsyncCallback\<boolean> | 是 | 回调函数。返回true表示是粘性公共事件;返回false表示不是粘性公共事件。 | | 678 | +| callback | AsyncCallback\<boolean> | 是 | 回调函数。当查询成功时,err为undefined,data为true表示是粘性公共事件,data为false表示不是粘性公共事件;否则err为错误对象。 | |
| 679 | 679 | ||
| 680 | **错误码:** | 680 | **错误码:** |
| 681 | 681 | ||
| @@ -690,7 +690,7 @@ isStickyCommonEvent(callback: AsyncCallback\<boolean>): void | |||
| 690 | <!--code_no_check--> | 690 | <!--code_no_check--> |
| 691 | 691 | ||
| 692 | ```ts | 692 | ```ts |
| 693 | -subscriber.isStickyCommonEvent((err: BusinessError, isSticky:boolean) => { | 693 | +subscriber.isStickyCommonEvent((err: BusinessError, isSticky: boolean) => { |
| 694 | if (err) { | 694 | if (err) { |
| 695 | console.error(`isStickyCommonEvent failed, code is ${err.code}, message is ${err.message}`); | 695 | console.error(`isStickyCommonEvent failed, code is ${err.code}, message is ${err.message}`); |
| 696 | return; | 696 | return; |
| @@ -703,9 +703,9 @@ subscriber.isStickyCommonEvent((err: BusinessError, isSticky:boolean) => { | |||
| 703 | 703 | ||
| 704 | isStickyCommonEvent(): Promise\<boolean> | 704 | isStickyCommonEvent(): Promise\<boolean> |
| 705 | 705 | ||
| 706 | -检查当前公共事件是否为一个粘性事件。使用Promise异步回调。 | 706 | +查询当前公共事件是否为一个粘性公共事件。使用Promise异步回调。 |
| 707 | 707 | ||
| 708 | -**系统能力:** `SystemCapability.Notification.CommonEvent` | 708 | +**系统能力:** SystemCapability.Notification.CommonEvent |
| 709 | 709 | ||
| 710 | **返回值:** | 710 | **返回值:** |
| 711 | 711 | ||
| @@ -718,7 +718,7 @@ isStickyCommonEvent(): Promise\<boolean> | |||
| 718 | <!--code_no_check--> | 718 | <!--code_no_check--> |
| 719 | 719 | ||
| 720 | ```ts | 720 | ```ts |
| 721 | -subscriber.isStickyCommonEvent().then((isSticky:boolean) => { | 721 | +subscriber.isStickyCommonEvent().then((isSticky: boolean) => { |
| 722 | console.info(`isStickyCommonEvent ${JSON.stringify(isSticky)}`); | 722 | console.info(`isStickyCommonEvent ${JSON.stringify(isSticky)}`); |
| 723 | }).catch((err: BusinessError) => { | 723 | }).catch((err: BusinessError) => { |
| 724 | console.error(`isStickyCommonEvent failed, code is ${err.code}, message is ${err.message}`); | 724 | console.error(`isStickyCommonEvent failed, code is ${err.code}, message is ${err.message}`); |
| @@ -731,7 +731,7 @@ isStickyCommonEventSync(): boolean | |||
| 731 | 731 | ||
| 732 | 检查当前公共事件是否为一个粘性事件。 | 732 | 检查当前公共事件是否为一个粘性事件。 |
| 733 | 733 | ||
| 734 | -**系统能力:** `SystemCapability.Notification.CommonEvent` | 734 | +**系统能力:** SystemCapability.Notification.CommonEvent |
| 735 | 735 | ||
| 736 | **返回值:** | 736 | **返回值:** |
| 737 | 737 | ||
| @@ -754,7 +754,7 @@ abortCommonEvent(callback: AsyncCallback\<void>): void | |||
| 754 | 754 | ||
| 755 | 添加有序公共事件的中止状态。当该接口与[finishCommonEvent](#finishcommonevent9)配合使用时,可以中止当前的有序公共事件,使该公共事件不再向下一个订阅者传递。使用callback异步回调。 | 755 | 添加有序公共事件的中止状态。当该接口与[finishCommonEvent](#finishcommonevent9)配合使用时,可以中止当前的有序公共事件,使该公共事件不再向下一个订阅者传递。使用callback异步回调。 |
| 756 | 756 | ||
| 757 | -**系统能力:** `SystemCapability.Notification.CommonEvent` | 757 | +**系统能力:** SystemCapability.Notification.CommonEvent |
| 758 | 758 | ||
| 759 | **参数:** | 759 | **参数:** |
| 760 | 760 | ||
| @@ -797,7 +797,7 @@ abortCommonEvent(): Promise\<void> | |||
| 797 | 797 | ||
| 798 | 添加有序公共事件的中止状态。当该接口与[finishCommonEvent](#finishcommonevent9)配合使用时,可以中止当前的有序公共事件,使该公共事件不再向下一个订阅者传递。使用Promise异步回调。 | 798 | 添加有序公共事件的中止状态。当该接口与[finishCommonEvent](#finishcommonevent9)配合使用时,可以中止当前的有序公共事件,使该公共事件不再向下一个订阅者传递。使用Promise异步回调。 |
| 799 | 799 | ||
| 800 | -**系统能力:** `SystemCapability.Notification.CommonEvent` | 800 | +**系统能力:** SystemCapability.Notification.CommonEvent |
| 801 | 801 | ||
| 802 | **返回值:** | 802 | **返回值:** |
| 803 | 803 | ||
| @@ -828,7 +828,7 @@ abortCommonEventSync(): void | |||
| 828 | 828 | ||
| 829 | 添加有序公共事件的中止状态。当该接口与[finishCommonEvent](#finishcommonevent9)配合使用时,可以中止当前的有序公共事件,使该公共事件不再向下一个订阅者传递。 | 829 | 添加有序公共事件的中止状态。当该接口与[finishCommonEvent](#finishcommonevent9)配合使用时,可以中止当前的有序公共事件,使该公共事件不再向下一个订阅者传递。 |
| 830 | 830 | ||
| 831 | -**系统能力:** `SystemCapability.Notification.CommonEvent` | 831 | +**系统能力:** SystemCapability.Notification.CommonEvent |
| 832 | 832 | ||
| 833 | **示例:** | 833 | **示例:** |
| 834 | 834 | ||
| @@ -849,7 +849,7 @@ clearAbortCommonEvent(callback: AsyncCallback\<void>): void | |||
| 849 | 849 | ||
| 850 | 清理有序公共事件的中止状态。当该接口与[finishCommonEvent](#finishcommonevent9)配合使用时,可以使该公共事件继续向下一个订阅者传递。使用callback异步回调。 | 850 | 清理有序公共事件的中止状态。当该接口与[finishCommonEvent](#finishcommonevent9)配合使用时,可以使该公共事件继续向下一个订阅者传递。使用callback异步回调。 |
| 851 | 851 | ||
| 852 | -**系统能力:** `SystemCapability.Notification.CommonEvent` | 852 | +**系统能力:** SystemCapability.Notification.CommonEvent |
| 853 | 853 | ||
| 854 | **参数:** | 854 | **参数:** |
| 855 | 855 | ||
| @@ -892,7 +892,7 @@ clearAbortCommonEvent(): Promise\<void> | |||
| 892 | 892 | ||
| 893 | 清理有序公共事件的中止状态。当该接口与[finishCommonEvent](#finishcommonevent9)配合使用时,可以使该公共事件继续向下一个订阅者传递。使用Promise异步回调。 | 893 | 清理有序公共事件的中止状态。当该接口与[finishCommonEvent](#finishcommonevent9)配合使用时,可以使该公共事件继续向下一个订阅者传递。使用Promise异步回调。 |
| 894 | 894 | ||
| 895 | -**系统能力:** `SystemCapability.Notification.CommonEvent` | 895 | +**系统能力:** SystemCapability.Notification.CommonEvent |
| 896 | 896 | ||
| 897 | **返回值:** | 897 | **返回值:** |
| 898 | 898 | ||
| @@ -923,7 +923,7 @@ clearAbortCommonEventSync(): void | |||
| 923 | 923 | ||
| 924 | 清理有序公共事件的中止状态。当该接口与[finishCommonEvent](#finishcommonevent9)配合使用时,可以使该公共事件继续向下一个订阅者传递。 | 924 | 清理有序公共事件的中止状态。当该接口与[finishCommonEvent](#finishcommonevent9)配合使用时,可以使该公共事件继续向下一个订阅者传递。 |
| 925 | 925 | ||
| 926 | -**系统能力:** `SystemCapability.Notification.CommonEvent` | 926 | +**系统能力:** SystemCapability.Notification.CommonEvent |
| 927 | 927 | ||
| 928 | **示例:** | 928 | **示例:** |
| 929 | 929 | ||
| @@ -944,13 +944,13 @@ getAbortCommonEvent(callback: AsyncCallback\<boolean>): void | |||
| 944 | 944 | ||
| 945 | 获取当前有序公共事件是否处于中止状态。使用callback异步回调。 | 945 | 获取当前有序公共事件是否处于中止状态。使用callback异步回调。 |
| 946 | 946 | ||
| 947 | -**系统能力:** `SystemCapability.Notification.CommonEvent` | 947 | +**系统能力:** SystemCapability.Notification.CommonEvent |
| 948 | 948 | ||
| 949 | **参数:** | 949 | **参数:** |
| 950 | 950 | ||
| 951 | | 参数名 | 类型 | 必填 | 说明 | | 951 | | 参数名 | 类型 | 必填 | 说明 | |
| 952 | | -------- | ----------------------- | ---- | ---------------------------------- | | 952 | | -------- | ----------------------- | ---- | ---------------------------------- | |
| 953 | -| callback | AsyncCallback\<boolean> | 是 | 回调函数。返回true表示当前有序公共事件处于中止状态;返回false表示当前有序公共事件没有处于中止状态。 | | 953 | +| callback | AsyncCallback\<boolean> | 是 | 当查询成功时,err为undefined,data为true表示当前有序公共事件处于中止状态,data为false表示当前有序公共事件没有处于中止状态;否则err为错误对象。 | |
| 954 | 954 | ||
| 955 | **错误码:** | 955 | **错误码:** |
| 956 | 956 | ||
| @@ -980,7 +980,7 @@ getAbortCommonEvent(): Promise\<boolean> | |||
| 980 | 980 | ||
| 981 | 获取当前有序公共事件是否处于中止状态。使用Promise异步回调。 | 981 | 获取当前有序公共事件是否处于中止状态。使用Promise异步回调。 |
| 982 | 982 | ||
| 983 | -**系统能力:** `SystemCapability.Notification.CommonEvent` | 983 | +**系统能力:** SystemCapability.Notification.CommonEvent |
| 984 | 984 | ||
| 985 | **返回值:** | 985 | **返回值:** |
| 986 | 986 | ||
| @@ -1006,13 +1006,13 @@ getAbortCommonEventSync(): boolean | |||
| 1006 | 1006 | ||
| 1007 | 获取当前有序公共事件是否处于中止状态。 | 1007 | 获取当前有序公共事件是否处于中止状态。 |
| 1008 | 1008 | ||
| 1009 | -**系统能力:** `SystemCapability.Notification.CommonEvent` | 1009 | +**系统能力:** SystemCapability.Notification.CommonEvent |
| 1010 | 1010 | ||
| 1011 | **返回值:** | 1011 | **返回值:** |
| 1012 | 1012 | ||
| 1013 | | 类型 | 说明 | | 1013 | | 类型 | 说明 | |
| 1014 | | ----------------- | ---------------------------------- | | 1014 | | ----------------- | ---------------------------------- | |
| 1015 | -| boolean |返回true表示当前有序公共事件处于中止状态;返回false表示当前有序公共事件没有处于中止状态。 | | 1015 | +| boolean | 返回true表示当前有序公共事件处于中止状态;返回false表示当前有序公共事件没有处于中止状态。 | |
| 1016 | 1016 | ||
| 1017 | **示例:** | 1017 | **示例:** |
| 1018 | 1018 | ||
| @@ -1031,13 +1031,13 @@ getSubscribeInfo(callback: AsyncCallback\<CommonEventSubscribeInfo>): void | |||
| 1031 | 1031 | ||
| 1032 | **原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 | 1032 | **原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 |
| 1033 | 1033 | ||
| 1034 | -**系统能力:** `SystemCapability.Notification.CommonEvent` | 1034 | +**系统能力:** SystemCapability.Notification.CommonEvent |
| 1035 | 1035 | ||
| 1036 | **参数:** | 1036 | **参数:** |
| 1037 | 1037 | ||
| 1038 | | 参数名 | 类型 | 必填 | 说明 | | 1038 | | 参数名 | 类型 | 必填 | 说明 | |
| 1039 | | -------- | ------------------------------------------------------------ | ---- | ---------------------- | | 1039 | | -------- | ------------------------------------------------------------ | ---- | ---------------------- | |
| 1040 | -| callback | AsyncCallback\<[CommonEventSubscribeInfo](./js-apis-inner-commonEvent-commonEventSubscribeInfo.md)> | 是 | 回调函数。返回订阅者的订阅信息。 | | 1040 | +| callback | AsyncCallback\<[CommonEventSubscribeInfo](./js-apis-inner-commonEvent-commonEventSubscribeInfo.md)> | 是 | 回调函数。当获取成功时,err为undefined,data为订阅者的订阅信息;否则err为错误对象 | |
| 1041 | 1041 | ||
| 1042 | **错误码:** | 1042 | **错误码:** |
| 1043 | 1043 | ||
| @@ -1069,7 +1069,7 @@ getSubscribeInfo(): Promise\<CommonEventSubscribeInfo> | |||
| 1069 | 1069 | ||
| 1070 | **原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 | 1070 | **原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 |
| 1071 | 1071 | ||
| 1072 | -**系统能力:** `SystemCapability.Notification.CommonEvent` | 1072 | +**系统能力:** SystemCapability.Notification.CommonEvent |
| 1073 | 1073 | ||
| 1074 | **返回值:** | 1074 | **返回值:** |
| 1075 | 1075 | ||
| @@ -1097,7 +1097,7 @@ getSubscribeInfoSync(): CommonEventSubscribeInfo | |||
| 1097 | 1097 | ||
| 1098 | **原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 | 1098 | **原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 |
| 1099 | 1099 | ||
| 1100 | -**系统能力:** `SystemCapability.Notification.CommonEvent` | 1100 | +**系统能力:** SystemCapability.Notification.CommonEvent |
| 1101 | 1101 | ||
| 1102 | **返回值:** | 1102 | **返回值:** |
| 1103 | 1103 | ||
| @@ -1110,8 +1110,8 @@ getSubscribeInfoSync(): CommonEventSubscribeInfo | |||
| 1110 | <!--code_no_check--> | 1110 | <!--code_no_check--> |
| 1111 | 1111 | ||
| 1112 | ```ts | 1112 | ```ts |
| 1113 | -let subscribeInfo1: commonEventManager.CommonEventSubscribeInfo = subscriber.getSubscribeInfoSync(); | 1113 | +let subscribeInfo: commonEventManager.CommonEventSubscribeInfo = subscriber.getSubscribeInfoSync(); |
| 1114 | -console.info(`Succeeded in getting subscribe info, subscribe info is ${JSON.stringify(subscribeInfo1)}`); | 1114 | +console.info(`Succeeded in getting subscribe info, subscribe info is ${JSON.stringify(subscribeInfo)}`); |
| 1115 | ``` | 1115 | ``` |
| 1116 | 1116 | ||
| 1117 | ### finishCommonEvent<sup>9+</sup> | 1117 | ### finishCommonEvent<sup>9+</sup> |
| @@ -1120,7 +1120,7 @@ finishCommonEvent(callback: AsyncCallback\<void>): void | |||
| 1120 | 1120 | ||
| 1121 | 用于订阅者结束对当前有序公共事件的处理。使用callback异步回调。 | 1121 | 用于订阅者结束对当前有序公共事件的处理。使用callback异步回调。 |
| 1122 | 1122 | ||
| 1123 | -**系统能力:** `SystemCapability.Notification.CommonEvent` | 1123 | +**系统能力:** SystemCapability.Notification.CommonEvent |
| 1124 | 1124 | ||
| 1125 | **参数:** | 1125 | **参数:** |
| 1126 | 1126 | ||
| @@ -1156,7 +1156,7 @@ finishCommonEvent(): Promise\<void> | |||
| 1156 | 1156 | ||
| 1157 | 用于订阅者结束对当前有序公共事件的处理。使用Promise异步回调。 | 1157 | 用于订阅者结束对当前有序公共事件的处理。使用Promise异步回调。 |
| 1158 | 1158 | ||
| 1159 | -**系统能力:** `SystemCapability.Notification.CommonEvent` | 1159 | +**系统能力:** SystemCapability.Notification.CommonEvent |
| 1160 | 1160 | ||
| 1161 | **返回值:** | 1161 | **返回值:** |
| 1162 | 1162 | ||
| @@ -1174,4 +1174,4 @@ subscriber.finishCommonEvent().then(() => { | |||
| 1174 | }).catch((err: BusinessError) => { | 1174 | }).catch((err: BusinessError) => { |
| 1175 | console.error(`Failed to finish common event. Code is ${err.code}, message is ${err.message}`); | 1175 | console.error(`Failed to finish common event. Code is ${err.code}, message is ${err.message}`); |
| 1176 | }); | 1176 | }); |
| 1177 | -``` | 1177 | +``` |
我看emitter的还没删,统一一下