• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Unsubscribing from Common Events in C
2
3
4## When to Use
5
6After completing service requirements, subscribers need to unsubscribe from common events.
7
8## Available APIs
9
10For details about the APIs, see [CommonEvent](../../reference/apis-basic-services-kit/capi-common-event.md).
11
12| API                              | Description                                                            |
13| ------------------------------------ | ---------------------------------------------------------------- |
14|[CommonEvent_ErrCode OH_CommonEvent_UnSubscribe(const CommonEvent_Subscriber* subscriber)](../../reference/apis-basic-services-kit/capi-common-event.md#oh_commonevent_unsubscribe)|Creates the subscriber information.|
15
16## How to Develop
17
181. Reference header files.
19
20   ```c++
21   #include <cstdint>
22   #include "hilog/log.h"
23   #include "BasicServicesKit/oh_commonevent.h"
24   ```
25
262. Add dynamic link libraries to the CMake script.
27
28   ```txt
29   target_link_libraries(entry PUBLIC
30       libace_napi.z.so
31       libhilog_ndk.z.so
32       libohcommonevent.so
33   )
34   ```
35
36
373. Unsubscribe from a common event.
38
39   After a subscriber subscribes to a common event and meets service requirements, the subscriber can use [OH_CommonEvent_UnSubscribe](../../reference/apis-basic-services-kit/capi-common-event.md#oh_commonevent_unsubscribe) to unsubscribe from the event.
40
41   ```c++
42   void Unsubscribe(CommonEvent_Subscriber* subscriber) {
43       // Unsubscribe from a common event by passing a subscriber.
44       int32_t ret = OH_CommonEvent_UnSubscribe(subscriber);
45       OH_LOG_Print(LOG_APP, LOG_INFO, 1, "CES_TEST", "OH_CommonEvent_UnSubscribe ret <%{public}d>.", ret);
46   }
47   ```
48