1# Unsubscribing from Common Events in C 2 3<!--Kit: Basic Services Kit--> 4<!--Subsystem: Notification--> 5<!--Owner: @peixu--> 6<!--Designer: @dongqingran; @wulong158--> 7<!--Tester: @wanghong1997--> 8<!--Adviser: @huipeizi--> 9 10## When to Use 11 12After completing service requirements, subscribers need to unsubscribe from common events. 13 14## Available APIs 15 16For details about the APIs, see [oh_commonevent.h](../../reference/apis-basic-services-kit/capi-oh-commonevent-h.md). 17 18| API | Description | 19| ------------------------------------ | ---------------------------------------------------------------- | 20|[CommonEvent_ErrCode OH_CommonEvent_UnSubscribe(const CommonEvent_Subscriber* subscriber)](../../reference/apis-basic-services-kit/capi-oh-commonevent-h.md#oh_commonevent_unsubscribe)|Unsubscribe from a common event.| 21 22## How to Develop 23 241. Reference header files. 25 26 ```c++ 27 #include <cstdint> 28 #include "hilog/log.h" 29 #include "BasicServicesKit/oh_commonevent.h" 30 ``` 31 322. Add dynamic link libraries to the CMake script. 33 34 ```txt 35 target_link_libraries(entry PUBLIC 36 libace_napi.z.so 37 libhilog_ndk.z.so 38 libohcommonevent.so 39 ) 40 ``` 41 42 433. Unsubscribe from a common event. 44 45 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-oh-commonevent-h.md#oh_commonevent_unsubscribe) to unsubscribe from the event. 46 47 ```c++ 48 void Unsubscribe(CommonEvent_Subscriber* subscriber) { 49 // Unsubscribe from a common event by passing a subscriber. 50 int32_t ret = OH_CommonEvent_UnSubscribe(subscriber); 51 OH_LOG_Print(LOG_APP, LOG_INFO, 1, "CES_TEST", "OH_CommonEvent_UnSubscribe ret <%{public}d>.", ret); 52 } 53 ``` 54