鸿蒙0基础学习【取消订阅公共事件(C/C++)】进程线程通信
·
场景介绍
订阅者在完成业务需求之后,需要取消订阅公共事件。
接口说明
| 接口名 | 描述 |
|---|---|
| [CommonEvent_ErrCode OH_CommonEvent_UnSubscribe(const CommonEvent_Subscriber* subscriber)] | 取消订阅公共事件。 |
开发步骤
- 引用头文件。
#include <cstdint>
#include "hilog/log.h"
#include "BasicServicesKit/oh_commonevent.h"
- 在CMake脚本中添加动态链接库。
target_link_libraries(entry PUBLIC
libace_napi.z.so
libhilog_ndk.z.so
libohcommonevent.so
)
-
取消订阅公共事件。
订阅者订阅公共事件并完成业务需求后,可以通过[OH_CommonEvent_UnSubscribe]主动取消订阅事件。
void Unsubscribe(CommonEvent_Subscriber* subscriber) {
// 通过传入订阅者来退订事件
int32_t ret = OH_CommonEvent_UnSubscribe(subscriber);
OH_LOG_Print(LOG_APP, LOG_INFO, 1, "CES_TEST", "OH_CommonEvent_UnSubscribe ret <%{public}d>.", ret);
}
更多推荐



所有评论(0)