提交 e0f0d81c 编写于 作者: F fangJinliang1

add interface

Signed-off-by: NfangJinliang1 <fangjinliang1@huawei.com>
Change-Id: Ie7cfd66da3a4a3f70ac6b8c2ea7be772e0e856d8
Signed-off-by: NfangJinliang1 <fangjinliang1@huawei.com>
上级 338fd314
......@@ -20,13 +20,11 @@ import CommonEventManager from '@ohos.commonEventManager';
## CommonEventManager.publish
```ts
publish(event: string, callback: AsyncCallback<void>): void
```
发布公共事件,并在发布后执行相应的回调函数。
**系统能力:** `SystemCapability.Notification.CommonEvent`
**系统能力:** SystemCapability.Notification.CommonEvent
**参数:**
......@@ -61,13 +59,11 @@ try {
## CommonEventManager.publish
```ts
publish(event: string, options: CommonEventPublishData, callback: AsyncCallback<void>): void
```
以回调的形式发布公共事件。
**系统能力:** `SystemCapability.Notification.CommonEvent`
**系统能力:**SystemCapability.Notification.CommonEvent
**参数:**
......@@ -110,13 +106,11 @@ try {
## CommonEventManager.publishAsUser<sup>
```ts
publishAsUser(event: string, userId: number, callback: AsyncCallback<void>): void
```
以回调的形式向指定用户发布公共事件。
**系统能力:** `SystemCapability.Notification.CommonEvent`
**系统能力:** SystemCapability.Notification.CommonEvent
**系统API**:此接口为系统接口,三方应用不支持调用。
......@@ -157,13 +151,11 @@ try {
## CommonEventManager.publishAsUser
```ts
publishAsUser(event: string, userId: number, options: CommonEventPublishData, callback: AsyncCallback<void>): void
```
以回调形式向指定用户发布公共事件并指定发布信息。
**系统能力:** `SystemCapability.Notification.CommonEvent`
**系统能力:** SystemCapability.Notification.CommonEvent
**系统API**:此接口为系统接口,三方应用不支持调用。
......@@ -212,13 +204,11 @@ try {
## CommonEventManager.createSubscriber
```ts
createSubscriber(subscribeInfo: CommonEventSubscribeInfo, callback: AsyncCallback<CommonEventSubscriber>): void
```
以回调形式创建订阅者。
**系统能力:** `SystemCapability.Notification.CommonEvent`
**系统能力:** SystemCapability.Notification.CommonEvent
**参数:**
......@@ -258,13 +248,11 @@ try {
## CommonEventManager.createSubscriber
```ts
createSubscriber(subscribeInfo: CommonEventSubscribeInfo): Promise<CommonEventSubscriber>
```
以Promise形式创建订阅者。
**系统能力:** `SystemCapability.Notification.CommonEvent`
**系统能力:** SystemCapability.Notification.CommonEvent
**参数:**
......@@ -299,13 +287,11 @@ CommonEventManager.createSubscriber(subscribeInfo).then((commonEventSubscriber)
## CommonEventManager.subscribe
```ts
subscribe(subscriber: CommonEventSubscriber, callback: AsyncCallback<CommonEventData>): void
```
以回调形式订阅公共事件。
**系统能力:** `SystemCapability.Notification.CommonEvent`
**系统能力:** SystemCapability.Notification.CommonEvent
**参数:**
......@@ -360,13 +346,11 @@ try {
## CommonEventManager.unsubscribe
```ts
unsubscribe(subscriber: CommonEventSubscriber, callback?: AsyncCallback<void>): void
```
以回调形式取消订阅公共事件。
**系统能力:** `SystemCapability.Notification.CommonEvent`
**系统能力:** SystemCapability.Notification.CommonEvent
**参数:**
......@@ -427,4 +411,69 @@ try {
} catch (err) {
console.error(`unsubscribe failed, code is ${err.code}, message is ${err.message}`);
}
```
\ No newline at end of file
```
## CommonEventManager.removeStickyCommonEvent<sup>10+</sup>
removeStickyCommonEvent(event: string, callback: AsyncCallback<void>): void
以回调形式移除粘性公共事件。
**系统能力:** SystemCapability.Notification.CommonEvent
**需要权限**: ohos.permission.COMMONEVENT_STICKY
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------------------- | ---- | -------------------------------- |
| event | string | 是 | 表示被移除的粘性公共事件。 |
| callback | AsyncCallback\<void> | 是 | 表示移除粘性公共事件的回调方法。 |
**示例:**
```ts
CommonEventManager.removeStickyCommonEvent("sticky_event", (err) => {
if (err) {
console.info(`Remove sticky event AsyncCallback failed, errCode: ${err.code}, errMes: ${err.message}`);
return;
}
console.info(`Remove sticky event AsyncCallback success`);
}
});
```
## CommonEventManager.removeStickyCommonEvent<sup>10+</sup>
removeStickyCommonEvent(event: string): Promise<void>
以Promise形式移除粘性公共事件。
**系统能力:** SystemCapability.Notification.CommonEvent
**需要权限**: ohos.permission.COMMONEVENT_STICKY
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| ------ | ------ | ---- | -------------------------- |
| event | string | 是 | 表示被移除的粘性公共事件。 |
**返回值:**
| 类型 | 说明 |
| -------------- | ---------------------------- |
| Promise\<void> | 表示移除粘性公共事件的对象。 |
**示例:**
```ts
commonEventManager.removeStickyCommonEvent("sticky_event").then(() => {
console.info(`Remove sticky event AsyncCallback success`);
}).catch ((err) => {
console.info(`Remove sticky event AsyncCallback failed, errCode: ${err.code}, errMes: ${err.message}`);
});
```
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册