From 05c91673cfed5e0922f4843c5bd002e4ad8d13ef Mon Sep 17 00:00:00 2001 From: zhuhan Date: Thu, 24 Aug 2023 20:19:47 +0800 Subject: [PATCH] fixed 116d239 from https://gitee.com/anluohan/docs/pulls/22949 add docs Signed-off-by: zhuhan Change-Id: I4f78671fa46b7c5c7a987bde57f3b205fd7e43f2 --- .../apis/js-apis-commonEventManager.md | 38 +++ ...inner-commonEvent-commonEventSubscriber.md | 232 ++++++++++++++++++ 2 files changed, 270 insertions(+) diff --git a/zh-cn/application-dev/reference/apis/js-apis-commonEventManager.md b/zh-cn/application-dev/reference/apis/js-apis-commonEventManager.md index 7cb58125b8..81ced42f91 100644 --- a/zh-cn/application-dev/reference/apis/js-apis-commonEventManager.md +++ b/zh-cn/application-dev/reference/apis/js-apis-commonEventManager.md @@ -312,6 +312,44 @@ CommonEventManager.createSubscriber(subscribeInfo).then((commonEventSubscriber) ``` +## CommonEventManager.createSubscriberSync + +createSubscriberSync(subscribeInfo: CommonEventSubscribeInfo): CommonEventSubscriber + +createSubscriber的同步接口。 + +**系统能力:** SystemCapability.Notification.CommonEvent + +**参数:** + +| 参数名 | 类型 | 必填 | 说明 | +| ------------- | ----------------------------------------------------- | ---- | -------------- | +| subscribeInfo | [CommonEventSubscribeInfo](./js-apis-inner-commonEvent-commonEventSubscribeInfo.md) | 是 | 表示订阅信息。 | + +**返回值:** +| 类型 | 说明 | +| --------------------------------------------------------- | ---------------- | +| [CommonEventSubscriber](./js-apis-inner-commonEvent-commonEventSubscriber.md) | 返回订阅者对象。 | + +**示例:** + +```ts +let subscriber; //用于保存创建成功的订阅者对象,后续使用其完成订阅及退订的动作 + +//订阅者信息 +let subscribeInfo = { + events: ["event"] +}; + +//创建订阅者 +try { + subscriber = CommonEventManager.createSubscriberSync(subscribeInfo); +} catch (err) { + console.error(`createSubscriberSync failed, code is ${err.code}, message is ${err.message}`); +} + +``` + ## CommonEventManager.subscribe subscribe(subscriber: CommonEventSubscriber, callback: AsyncCallback\): void diff --git a/zh-cn/application-dev/reference/apis/js-apis-inner-commonEvent-commonEventSubscriber.md b/zh-cn/application-dev/reference/apis/js-apis-inner-commonEvent-commonEventSubscriber.md index caa6b850cd..ba96ba2503 100644 --- a/zh-cn/application-dev/reference/apis/js-apis-inner-commonEvent-commonEventSubscriber.md +++ b/zh-cn/application-dev/reference/apis/js-apis-inner-commonEvent-commonEventSubscriber.md @@ -83,6 +83,27 @@ subscriber.getCode().then((code) => { }); ``` +## getCodeSync + +getCodeSync(): number + +getCode的同步接口 + +**系统能力**:`SystemCapability.Notification.CommonEvent` + +**返回值:** + +| 类型 | 说明 | +| ---------------- | -------------------- | +| number | 公共事件代码。 | + +**示例:** + +```ts +let code = subscriber.getCodeSync(); +console.info("getCodeSync " + JSON.stringify(code)); +``` + ## setCode setCode(code: number, callback: AsyncCallback\): void @@ -142,6 +163,32 @@ subscriber.setCode(1).then(() => { }); ``` +## setCodeSync + +setCodeSync(code: number): void + +setCode的同步接口 + +**系统能力**:`SystemCapability.Notification.CommonEvent` + +**参数:** + +| 参数名 | 类型 | 必填 | 说明 | +| ------ | ------ | ---- | ------------------ | +| code | number | 是 | 公共事件的代码。 | + + +**示例:** + +```ts + +try { + subscriber.setCodeSync(1); +} catch (err) { + console.error(`setCodeSync failed, code is ${err.code}, message is ${err.message}`); +} +``` + ## getData getData(callback: AsyncCallback\): void @@ -194,6 +241,27 @@ subscriber.getData().then((data) => { }); ``` +## getDataSync + +getDataSync(): string + +getData的同步接口 + +**系统能力**:`SystemCapability.Notification.CommonEvent` + +**返回值:** + +| 类型 | 说明 | +| ---------------- | ------------------ | +| string | 公共事件的数据。 | + +**示例:** + +```ts +let data = subscriber.getDataSync(); +console.info("getDataSync " + JSON.stringify(data)); +``` + ## setData setData(data: string, callback: AsyncCallback\): void @@ -253,6 +321,29 @@ subscriber.setData("publish_data_changed").then(() => { }); ``` +## setDataSync +setDataSync(data: string): void + +setData的同步接口。 + +**系统能力**:`SystemCapability.Notification.CommonEvent` + +**参数:** + +| 参数名 | 类型 | 必填 | 说明 | +| ------ | ------ | ---- | -------------------- | +| data | string | 是 | 公共事件的数据。 | + +**示例:** + +```ts +try { + subscriber.setDataSync("publish_data_changed"); +} catch (err) { + console.error(`setDataSync failed, code is ${err.code}, message is ${err.message}`); +} +``` + ## setCodeAndData setCodeAndData(code: number, data: string, callback:AsyncCallback\): void @@ -314,6 +405,31 @@ subscriber.setCodeAndData(1, "publish_data_changed").then(() => { }); ``` +## setCodeAndDataSync + +setCodeAndData的同步接口。 + +setCodeAndDataSync(code: number, data: string): void + +**系统能力**:`SystemCapability.Notification.CommonEvent` + +**参数:** + +| 参数名 | 类型 | 必填 | 说明 | +| ------ | ------ | ---- | -------------------- | +| code | number | 是 | 公共事件的代码。 | +| data | string | 是 | 公共事件的数据。 | + +**示例:** + +```ts +try { + subscriber.setCodeAndDataSync(1, "publish_data_changed"); +} catch (err) { + console.error(`setCodeAndData failed, code is ${err.code}, message is ${err.message}`); +} + +``` ## isOrderedCommonEvent isOrderedCommonEvent(callback: AsyncCallback\): void @@ -370,6 +486,29 @@ subscriber.isOrderedCommonEvent().then((isOrdered) => { }); ``` +## isOrderedCommonEventSync + +isOrderedCommonEventSync(): boolean + +isOrderedCommonEvent的同步接口 + +返回true代表是有序公共事件,false代表不是有序公共事件。 + +**系统能力**:`SystemCapability.Notification.CommonEvent` + +**返回值:** + +| 类型 | 说明 | +| ----------------- | -------------------------------- | +| boolean | 当前公共事件的是否为有序公共事件。 | + +**示例:** + +```ts +let isOrdered = subscriber.isOrderedCommonEventSync(); +console.info("isOrdered " + JSON.stringify(isOrdered)); +``` + ## isStickyCommonEvent isStickyCommonEvent(callback: AsyncCallback\): void @@ -426,6 +565,29 @@ subscriber.isStickyCommonEvent().then((isSticky) => { }); ``` +## isStickyCommonEventSync + +isStickyCommonEventSync(): boolean + +isStickyCommonEvent的同步接口。 + +返回true代表是粘性公共事件,false代表不是粘性公共事件。 + +**系统能力**:`SystemCapability.Notification.CommonEvent` + +**返回值:** + +| 类型 | 说明 | +| ----------------- | -------------------------------- | +| boolean | 当前公共事件的是否为粘性公共事件。 | + +**示例:** + +```ts +let isSticky = subscriber.isStickyCommonEventSync(); +console.info("isSticky " + JSON.stringify(isSticky)); +``` + ## abortCommonEvent abortCommonEvent(callback: AsyncCallback\): void @@ -478,6 +640,20 @@ subscriber.abortCommonEvent().then(() => { }); ``` +## abortCommonEventSync + +abortCommonEventSync(): void + +abortCommonEvent的同步接口 + +**系统能力**:`SystemCapability.Notification.CommonEvent` + +**示例:** + +```ts +subscriber.abortCommonEventSync(); +``` + ## clearAbortCommonEvent clearAbortCommonEvent(callback: AsyncCallback\): void @@ -530,6 +706,20 @@ subscriber.clearAbortCommonEvent().then(() => { }); ``` +## clearAbortCommonEventSync + +clearAbortCommonEventSync(): void + +clearAbortCommonEvent的同步接口 + +**系统能力**:`SystemCapability.Notification.CommonEvent` + +**示例:** + +```ts +subscriber.clearAbortCommonEventSync(); +``` + ## getAbortCommonEvent getAbortCommonEvent(callback: AsyncCallback\): void @@ -582,6 +772,27 @@ subscriber.getAbortCommonEvent().then((abortEvent) => { }); ``` +## getAbortCommonEventSync + +getAbortCommonEventSync(): boolean + +getAbortCommonEvent的同步接口。 + +**系统能力**:`SystemCapability.Notification.CommonEvent` + +**返回值:** + +| 类型 | 说明 | +| ----------------- | ---------------------------------- | +| boolean | 表示当前有序公共事件是否取消的状态。 | + +**示例:** + +```ts +let abortEvent = subscriber.getAbortCommonEventSync(); +console.info("getAbortCommonEventSync " + JSON.stringify(abortEvent)); +``` + ## getSubscribeInfo getSubscribeInfo(callback: AsyncCallback\): void @@ -634,6 +845,27 @@ subscriber.getSubscribeInfo().then((subscribeInfo) => { }); ``` +## getSubscribeInfoSync + +getSubscribeInfoSync(): CommonEventSubscribeInfo + +getSubscribeInfo的同步接口。 + +**系统能力**:`SystemCapability.Notification.CommonEvent` + +**返回值:** + +| 类型 | 说明 | +| ------------------------------------------------------------ | ---------------------- | +| [CommonEventSubscribeInfo](./js-apis-inner-commonEvent-commonEventSubscribeInfo.md) | 表示订阅者的订阅信息。 | + +**示例:** + +```ts +let subscribeInfo = subscriber.getSubscribeInfoSync(); +console.info("subscribeInfo " + JSON.stringify(subscribeInfo)); +``` + ## finishCommonEvent9+ finishCommonEvent(callback: AsyncCallback\): void -- GitLab