Public Event Publishing
Note:
Currently in the beta phase.
Scenario Description
When needing to publish a custom public event, you can use the publish() method to publish the event. Published public events can carry data for subscribers to parse and process further.
Note:
Sticky public events that have already been sent can still be received by later subscribers. Other public events require subscription before reception. For subscription details, refer to the Public Event Subscription Section.
Interface Description
For detailed interface information, please refer to the Interface Documentation.
| Interface Name | Description |
|---|---|
| publish(event: String): Unit | Publish a public event. |
| publish(event: String, options: CommonEventPublishData): Unit | Publish a public event with specified information. |
Publishing Public Events Without Carrying Information
Public events without carrying information can only publish unordered public events.
-
Import the module.
import kit.BasicServicesKit.* -
Pass the event name to be published and the callback function to publish the event.
// Publish a public event, where the event field should be replaced with the actual event name. let support1 = Support.COMMON_EVENT_SCREEN_ON CommonEventManager.publish(support1)
Publishing Public Events Carrying Information
Public events carrying information can be published as unordered public events, ordered public events, or sticky events. This can be configured via the isOrdered and isSticky fields in the CommonEventPublishData parameter.
-
Import the module.
import kit.BasicServicesKit.* -
Construct the public event information to be published.
// Public event related information let pData = CommonEventPublishData( bundleName: "com.example.myapplication", data: "newbee", code: 123321, subscriberPermissions: Array<String>(), isOrdered: false, isSticky: false, parameters: HashMap<String, ValueType>() ) -
Pass the event name to be published, the specified information to be published, and the callback function to publish the event.
// Publish a public event, where the event field should be replaced with the actual event name let support1 = Support.COMMON_EVENT_SCREEN_ON CommonEventManager.publish(support1, options: pData)