diff --git a/en/application-dev/notification/notification-with-wantagent.md b/en/application-dev/notification/notification-with-wantagent.md index 4a820360cc5f5f1c4ca829a629636dac0a672371..72e845497eac1cff153ebd7bf9d9af069b1bab6f 100644 --- a/en/application-dev/notification/notification-with-wantagent.md +++ b/en/application-dev/notification/notification-with-wantagent.md @@ -40,7 +40,7 @@ For details about the APIs, see [@ohos.app.ability.wantAgent](../reference/apis/ Scenario 1: Create a [WantAgentInfo](../reference/apis/js-apis-inner-wantAgent-wantAgentInfo.md) object for starting a UIAbility component. ```typescript - let wantAgentObj:WantAgent = null; // Save the WantAgent object created. It will be used to complete the trigger operations. + let wantAgentObj:WantAgent; // Save the WantAgent object created. It will be used to complete the trigger operations. // Set the action type through operationType of WantAgentInfo. let wantAgentInfo:wantAgent.WantAgentInfo = { @@ -64,7 +64,7 @@ For details about the APIs, see [@ohos.app.ability.wantAgent](../reference/apis/ Scenario 2: Create a [WantAgentInfo](../reference/apis/js-apis-inner-wantAgent-wantAgentInfo.md) object for publishing a [common event](../application-models/common-event-overview.md). ```typescript - let wantAgentObj:WantAgent = null; // Save the WantAgent object created. It will be used to complete the trigger operations. + let wantAgentObj:WantAgent; // Save the WantAgent object created. It will be used to complete the trigger operations. // Set the action type through operationType of WantAgentInfo. let wantAgentInfo:wantAgent.WantAgentInfo = { diff --git a/en/application-dev/reference/apis/js-apis-commonEventManager.md b/en/application-dev/reference/apis/js-apis-commonEventManager.md index 070fee6a9381edfea0ceaf7758b01f41a137b861..1754dc36d54e935f38b617be757528f45c7fcd17 100644 --- a/en/application-dev/reference/apis/js-apis-commonEventManager.md +++ b/en/application-dev/reference/apis/js-apis-commonEventManager.md @@ -60,7 +60,8 @@ function publishCB(err:Base.BusinessError) { // Publish a common event. try { CommonEventManager.publish("event", publishCB); -} catch(err) { +} catch (error) { + let err:Base.BusinessError = error as Base.BusinessError; console.error(`publish failed, code is ${err.code}, message is ${err.message}`); } ``` @@ -114,7 +115,8 @@ function publishCB(err:Base.BusinessError) { // Publish a common event. try { CommonEventManager.publish("event", options, publishCB); -} catch (err) { +} catch (error) { + let err:Base.BusinessError = error as Base.BusinessError; console.error(`publish failed, code is ${err.code}, message is ${err.message}`); } ``` @@ -166,7 +168,8 @@ let userId = 100; // Publish a common event. try { CommonEventManager.publishAsUser("event", userId, publishCB); -} catch (err) { +} catch (error) { + let err:Base.BusinessError = error as Base.BusinessError; console.error(`publishAsUser failed, code is ${err.code}, message is ${err.message}`); } ``` @@ -226,7 +229,8 @@ let userId = 100; // Publish a common event. try { CommonEventManager.publishAsUser("event", userId, options, publishCB); -} catch (err) { +} catch (error) { + let err:Base.BusinessError = error as Base.BusinessError; console.error(`publishAsUser failed, code is ${err.code}, message is ${err.message}`); } ``` @@ -269,7 +273,8 @@ function createCB(err:Base.BusinessError, commonEventSubscriber:CommonEventManag // Create a subscriber. try { CommonEventManager.createSubscriber(subscribeInfo, createCB); -} catch (err) { +} catch (error) { + let err:Base.BusinessError = error as Base.BusinessError; console.error(`createSubscriber failed, code is ${err.code}, message is ${err.message}`); } ``` @@ -366,7 +371,8 @@ function createCB(err:Base.BusinessError, commonEventSubscriber:CommonEventManag // Subscribe to a common event. try { CommonEventManager.subscribe(subscriber, SubscribeCB); - } catch (err) { + } catch (error) { + let err:Base.BusinessError = error as Base.BusinessError; console.error(`subscribe failed, code is ${err.code}, message is ${err.message}`); } } else { @@ -377,7 +383,8 @@ function createCB(err:Base.BusinessError, commonEventSubscriber:CommonEventManag // Create a subscriber. try { CommonEventManager.createSubscriber(subscribeInfo, createCB); -} catch (err) { +} catch (error) { + let err:Base.BusinessError = error as Base.BusinessError; console.error(`createSubscriber failed, code is ${err.code}, message is ${err.message}`); } ``` @@ -433,7 +440,8 @@ function createCB(err:Base.BusinessError, commonEventSubscriber:CommonEventManag // Subscribe to a common event. try { CommonEventManager.subscribe(subscriber, subscribeCB); - } catch(err) { + } catch (error) { + let err:Base.BusinessError = error as Base.BusinessError; console.error(`subscribe failed, code is ${err.code}, message is ${err.message}`); } } @@ -449,14 +457,16 @@ function unsubscribeCB(err:Base.BusinessError) { // Create a subscriber. try { CommonEventManager.createSubscriber(subscribeInfo, createCB); -} catch (err) { +} catch (error) { + let err:Base.BusinessError = error as Base.BusinessError; console.error(`createSubscriber failed, code is ${err.code}, message is ${err.message}`); } // Unsubscribe from the common event. try { CommonEventManager.unsubscribe(subscriber, unsubscribeCB); -} catch (err) { +} catch (error) { + let err:Base.BusinessError = error as Base.BusinessError; console.error(`unsubscribe failed, code is ${err.code}, message is ${err.message}`); } ``` @@ -583,7 +593,7 @@ CommonEventManager.setStaticSubscriberState(true, (err:Base.BusinessError) => { console.info(`Set static subscriber state callback failed, err is null.`); return; } - if (err.code) { + if (err.code !== undefined && err.code != null) { console.info(`Set static subscriber state callback failed, errCode: ${err.code}, errMes: ${err.message}`); return; } diff --git a/en/application-dev/reference/apis/js-apis-inner-commonEvent-commonEventSubscriber.md b/en/application-dev/reference/apis/js-apis-inner-commonEvent-commonEventSubscriber.md index cc3d507ee9d208bc66571ca56daf1cf518c3d5fe..f0d740a85d874d643838135e2bc83232ab86a62d 100644 --- a/en/application-dev/reference/apis/js-apis-inner-commonEvent-commonEventSubscriber.md +++ b/en/application-dev/reference/apis/js-apis-inner-commonEvent-commonEventSubscriber.md @@ -21,7 +21,7 @@ let subscribeInfo:CommonEventManager.CommonEventSubscribeInfo = { // Callback for subscriber creation. function createCB(err:Base.BusinessError, commonEventSubscriber:CommonEventManager.CommonEventSubscriber) { - if (err.code) { + if (err.code !== undefined && err.code != null) { console.error(`createSubscriber failed, code is ${err.code}`); } else { console.info("createSubscriber"); @@ -52,7 +52,7 @@ Obtains the code of this common event. This API uses an asynchronous callback to ```ts // Callback for result code obtaining of an ordered common event. function getCodeCB(err:Base.BusinessError, code:number) { - if (err.code) { + if (err.code !== undefined && err.code != null) { console.error(`getCode failed, code is ${err.code}, message is ${err.message}`); } else { console.info("getCode " + JSON.stringify(code)); @@ -105,7 +105,7 @@ Sets the code for this common event. This API uses an asynchronous callback to r ```ts // Callback for result code setting of an ordered common event. function setCodeCB(err:Base.BusinessError) { - if (err.code) { + if (err.code !== undefined && err.code != null) { console.error(`setCode failed, code is ${err.code}, message is ${err.message}`); } else { console.info("setCode"); @@ -163,7 +163,7 @@ Obtains the data of this common event. This API uses an asynchronous callback to ```ts // Callback for result data obtaining of an ordered common event. function getDataCB(err:Base.BusinessError, data:string) { - if (err.code) { + if (err.code !== undefined && err.code != null) { console.error(`getData failed, code is ${err.code}, message is ${err.message}`); } else { console.info("getData " + JSON.stringify(data)); @@ -216,7 +216,7 @@ Sets the data for this common event. This API uses an asynchronous callback to r ```ts // Callback for result data setting of an ordered common event function setDataCB(err:Base.BusinessError) { - if (err.code) { + if (err.code !== undefined && err.code != null) { console.error(`setCode failed, code is ${err.code}, message is ${err.message}`); } else { console.info("setData"); @@ -276,7 +276,7 @@ Sets the code and data for this common event. This API uses an asynchronous call ```ts // Callback for code and data setting of an ordered common event. function setCodeDataCB(err:Base.BusinessError) { - if (err.code) { + if (err.code !== undefined && err.code != null) { console.error(`setCodeAndData failed, code is ${err.code}, message is ${err.message}`); } else { console.info("setCodeDataCallback"); @@ -335,7 +335,7 @@ Checks whether this common event is an ordered one. This API uses an asynchronou ```ts // Callback for checking whether the current common event is an ordered one. function isOrderedCB(err:Base.BusinessError, isOrdered:boolean) { - if (err.code) { + if (err.code !== undefined && err.code != null) { console.error(`isOrderedCommonEvent failed, code is ${err.code}, message is ${err.message}`); } else { console.info("isOrdered " + JSON.stringify(isOrdered)); @@ -387,7 +387,7 @@ Checks whether this common event is a sticky one. This API uses an asynchronous ```ts // Callback for checking whether the current common event is a sticky one. function isStickyCB(err:Base.BusinessError, isSticky:boolean) { - if (err.code) { + if (err.code !== undefined && err.code != null) { console.error(`isStickyCommonEvent failed, code is ${err.code}, message is ${err.message}`); } else { console.info("isSticky " + JSON.stringify(isSticky)); @@ -439,7 +439,7 @@ Aborts this common event. After the abort, the common event is not sent to the n ```ts // Callback for common event aborting. function abortCB(err:Base.BusinessError) { - if (err.code) { + if (err.code !== undefined && err.code != null) { console.error(`abortCommonEvent failed, code is ${err.code}, message is ${err.message}`); } else { console.info("abortCommonEvent"); @@ -491,7 +491,7 @@ Clears the aborted state of this common event. This API takes effect only for or ```ts // Callback for clearing the aborted state of the current common event. function clearAbortCB(err:Base.BusinessError) { - if (err.code) { + if (err.code !== undefined && err.code != null) { console.error(`clearAbortCommonEvent failed, code is ${err.code}, message is ${err.message}`); } else { console.info("clearAbortCommonEvent"); @@ -543,7 +543,7 @@ Checks whether this common event is in the aborted state. This API takes effect ```ts // Callback for checking whether the current common event is in the aborted state. function getAbortCB(err:Base.BusinessError, abortEvent:boolean) { - if (err.code) { + if (err.code !== undefined && err.code != null) { console.error(`getAbortCommonEvent failed, code is ${err.code}, message is ${err.message}`); } else { console.info("abortCommonEvent " + abortEvent) @@ -595,7 +595,7 @@ Obtains the subscriber information. This API uses an asynchronous callback to re ```ts // Callback for subscriber information obtaining. function getCB(err:Base.BusinessError, subscribeInfo:CommonEventManager.CommonEventSubscribeInfo) { - if (err.code) { + if (err.code !== undefined && err.code != null) { console.error(`getSubscribeInfo failed, code is ${err.code}, message is ${err.message}`); } else { console.info("subscribeInfo " + JSON.stringify(subscribeInfo)); @@ -647,7 +647,7 @@ Finishes this common event. This API takes effect only for ordered common events ```ts // Callback for ordered common event finishing. function finishCB(err:Base.BusinessError) { - if (err.code) { + if (err.code !== undefined && err.code != null) { console.error(`finishCommonEvent failed, code is ${err.code}, message is ${err.message}`); } else { console.info("FinishCommonEvent"); diff --git a/zh-cn/application-dev/notification/notification-with-wantagent.md b/zh-cn/application-dev/notification/notification-with-wantagent.md index 3cc82b5c38e202d22321874b1b31034fa43ae324..e187b37e95ca008b4f88689a6e53537732dfbf8b 100644 --- a/zh-cn/application-dev/notification/notification-with-wantagent.md +++ b/zh-cn/application-dev/notification/notification-with-wantagent.md @@ -39,7 +39,7 @@ 场景一:创建拉起UIAbility的WantAgent的[WantAgentInfo](../reference/apis/js-apis-inner-wantAgent-wantAgentInfo.md)信息。 ```typescript - let wantAgentObj:WantAgent = null; // 用于保存创建成功的wantAgent对象,后续使用其完成触发的动作。 + let wantAgentObj:WantAgent; // 用于保存创建成功的wantAgent对象,后续使用其完成触发的动作。 // 通过WantAgentInfo的operationType设置动作类型 let wantAgentInfo:wantAgent.WantAgentInfo = { @@ -63,7 +63,7 @@ 场景二:创建发布[公共事件](../application-models/common-event-overview.md)的WantAgent的[WantAgentInfo](../reference/apis/js-apis-inner-wantAgent-wantAgentInfo.md)信息。 ```typescript - let wantAgentObj:WantAgent = null; // 用于保存创建成功的WantAgent对象,后续使用其完成触发的动作。 + let wantAgentObj:WantAgent; // 用于保存创建成功的WantAgent对象,后续使用其完成触发的动作。 // 通过WantAgentInfo的operationType设置动作类型 let wantAgentInfo:wantAgent.WantAgentInfo = { 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 b9b9a51618bf6e950636f3f5b0ea84efd410bfcb..29ba3cd215d3369d31a5a3b24dd7d80287c31c85 100644 --- a/zh-cn/application-dev/reference/apis/js-apis-commonEventManager.md +++ b/zh-cn/application-dev/reference/apis/js-apis-commonEventManager.md @@ -60,7 +60,8 @@ function publishCB(err:Base.BusinessError) { //发布公共事件 try { CommonEventManager.publish("event", publishCB); -} catch(err) { +} catch (error) { + let err:Base.BusinessError = error as Base.BusinessError; console.error(`publish failed, code is ${err.code}, message is ${err.message}`); } ``` @@ -114,7 +115,8 @@ function publishCB(err:Base.BusinessError) { //发布公共事件 try { CommonEventManager.publish("event", options, publishCB); -} catch (err) { +} catch (error) { + let err:Base.BusinessError = error as Base.BusinessError; console.error(`publish failed, code is ${err.code}, message is ${err.message}`); } ``` @@ -166,7 +168,8 @@ let userId = 100; //发布公共事件 try { CommonEventManager.publishAsUser("event", userId, publishCB); -} catch (err) { +} catch (error) { + let err:Base.BusinessError = error as Base.BusinessError; console.error(`publishAsUser failed, code is ${err.code}, message is ${err.message}`); } ``` @@ -226,7 +229,8 @@ let userId = 100; //发布公共事件 try { CommonEventManager.publishAsUser("event", userId, options, publishCB); -} catch (err) { +} catch (error) { + let err:Base.BusinessError = error as Base.BusinessError; console.error(`publishAsUser failed, code is ${err.code}, message is ${err.message}`); } ``` @@ -269,7 +273,8 @@ function createCB(err:Base.BusinessError, commonEventSubscriber:CommonEventManag //创建订阅者 try { CommonEventManager.createSubscriber(subscribeInfo, createCB); -} catch (err) { +} catch (error) { + let err:Base.BusinessError = error as Base.BusinessError; console.error(`createSubscriber failed, code is ${err.code}, message is ${err.message}`); } ``` @@ -345,7 +350,8 @@ let subscribeInfo = { //创建订阅者 try { subscriber = CommonEventManager.createSubscriberSync(subscribeInfo); -} catch (err) { +} catch (error) { + let err:Base.BusinessError = error as Base.BusinessError; console.error(`createSubscriberSync failed, code is ${err.code}, message is ${err.message}`); } @@ -404,7 +410,8 @@ function createCB(err:Base.BusinessError, commonEventSubscriber:CommonEventManag //订阅公共事件 try { CommonEventManager.subscribe(subscriber, SubscribeCB); - } catch (err) { + } catch (error) { + let err:Base.BusinessError = error as Base.BusinessError; console.error(`subscribe failed, code is ${err.code}, message is ${err.message}`); } } else { @@ -415,7 +422,8 @@ function createCB(err:Base.BusinessError, commonEventSubscriber:CommonEventManag //创建订阅者 try { CommonEventManager.createSubscriber(subscribeInfo, createCB); -} catch (err) { +} catch (error) { + let err:Base.BusinessError = error as Base.BusinessError; console.error(`createSubscriber failed, code is ${err.code}, message is ${err.message}`); } ``` @@ -471,7 +479,8 @@ function createCB(err:Base.BusinessError, commonEventSubscriber:CommonEventManag //订阅公共事件 try { CommonEventManager.subscribe(subscriber, subscribeCB); - } catch(err) { + } catch (error) { + let err:Base.BusinessError = error as Base.BusinessError; console.error(`subscribe failed, code is ${err.code}, message is ${err.message}`); } } @@ -487,14 +496,16 @@ function unsubscribeCB(err:Base.BusinessError) { //创建订阅者 try { CommonEventManager.createSubscriber(subscribeInfo, createCB); -} catch (err) { +} catch (error) { + let err:Base.BusinessError = error as Base.BusinessError; console.error(`createSubscriber failed, code is ${err.code}, message is ${err.message}`); } //取消订阅公共事件 try { CommonEventManager.unsubscribe(subscriber, unsubscribeCB); -} catch (err) { +} catch (error) { + let err:Base.BusinessError = error as Base.BusinessError; console.error(`unsubscribe failed, code is ${err.code}, message is ${err.message}`); } ``` @@ -621,7 +632,7 @@ CommonEventManager.setStaticSubscriberState(true, (err:Base.BusinessError) => { console.info(`Set static subscriber state callback failed, err is null.`); return; } - if (err.code) { + if (err.code !== undefined && err.code != null) { console.info(`Set static subscriber state callback failed, errCode: ${err.code}, errMes: ${err.message}`); return; } 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 d9f1fbe39ccecae28723b12a8e05f4cdda8d1ef4..e8067cb831a4babe00b1b6df36ac235f1c12ec87 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 @@ -21,7 +21,7 @@ let subscribeInfo:CommonEventManager.CommonEventSubscribeInfo = { // 创建订阅者回调 function createCB(err:Base.BusinessError, commonEventSubscriber:CommonEventManager.CommonEventSubscriber) { - if (err.code) { + if (err.code !== undefined && err.code != null) { console.error(`createSubscriber failed, code is ${err.code}`); } else { console.info("createSubscriber"); @@ -52,7 +52,7 @@ getCode(callback: AsyncCallback\): void ```ts //获取有序公共事件代码回调 function getCodeCB(err:Base.BusinessError, code:number) { - if (err.code) { + if (err.code !== undefined && err.code != null) { console.error(`getCode failed, code is ${err.code}, message is ${err.message}`); } else { console.info("getCode " + JSON.stringify(code)); @@ -126,7 +126,7 @@ setCode(code: number, callback: AsyncCallback\): void ```ts //设置有序公共事件的代码回调 function setCodeCB(err:Base.BusinessError) { - if (err.code) { + if (err.code !== undefined && err.code != null) { console.error(`setCode failed, code is ${err.code}, message is ${err.message}`); } else { console.info("setCode"); @@ -210,7 +210,7 @@ getData(callback: AsyncCallback\): void ```ts //获取有序公共事件代码数据回调 function getDataCB(err:Base.BusinessError, data:string) { - if (err.code) { + if (err.code !== undefined && err.code != null) { console.error(`getData failed, code is ${err.code}, message is ${err.message}`); } else { console.info("getData " + JSON.stringify(data)); @@ -284,7 +284,7 @@ setData(data: string, callback: AsyncCallback\): void ```ts //设置有序公共事件的结果数据回调 function setDataCB(err:Base.BusinessError) { - if (err.code) { + if (err.code !== undefined && err.code != null) { console.error(`setCode failed, code is ${err.code}, message is ${err.message}`); } else { console.info("setData"); @@ -367,7 +367,7 @@ setCodeAndData(code: number, data: string, callback:AsyncCallback\): void ```ts //设置有序公共事件的代码和数据回调 function setCodeDataCB(err:Base.BusinessError) { - if (err.code) { + if (err.code !== undefined && err.code != null) { console.error(`setCodeAndData failed, code is ${err.code}, message is ${err.message}`); } else { console.info("setCodeDataCallback"); @@ -453,7 +453,7 @@ isOrderedCommonEvent(callback: AsyncCallback\): void ```ts //获取当前公共事件是否为有序事件的回调 function isOrderedCB(err:Base.BusinessError, isOrdered:boolean) { - if (err.code) { + if (err.code !== undefined && err.code != null) { console.error(`isOrderedCommonEvent failed, code is ${err.code}, message is ${err.message}`); } else { console.info("isOrdered " + JSON.stringify(isOrdered)); @@ -532,7 +532,7 @@ isStickyCommonEvent(callback: AsyncCallback\): void ```ts //获取当前公共事件是否为粘性事件的回调 function isStickyCB(err:Base.BusinessError, isSticky:boolean) { - if (err.code) { + if (err.code !== undefined && err.code != null) { console.error(`isStickyCommonEvent failed, code is ${err.code}, message is ${err.message}`); } else { console.info("isSticky " + JSON.stringify(isSticky)); @@ -609,7 +609,7 @@ abortCommonEvent(callback: AsyncCallback\): void ```ts //取消当前有序公共事件的回调 function abortCB(err:Base.BusinessError) { - if (err.code) { + if (err.code !== undefined && err.code != null) { console.error(`abortCommonEvent failed, code is ${err.code}, message is ${err.message}`); } else { console.info("abortCommonEvent"); @@ -675,7 +675,7 @@ clearAbortCommonEvent(callback: AsyncCallback\): void ```ts //清除当前公共事件取消状态的回调 function clearAbortCB(err:Base.BusinessError) { - if (err.code) { + if (err.code !== undefined && err.code != null) { console.error(`clearAbortCommonEvent failed, code is ${err.code}, message is ${err.message}`); } else { console.info("clearAbortCommonEvent"); @@ -741,7 +741,7 @@ getAbortCommonEvent(callback: AsyncCallback\): void ```ts //获取当前有序公共事件是否取消的回调 function getAbortCB(err:Base.BusinessError, abortEvent:boolean) { - if (err.code) { + if (err.code !== undefined && err.code != null) { console.error(`getAbortCommonEvent failed, code is ${err.code}, message is ${err.message}`); } else { console.info("abortCommonEvent " + abortEvent) @@ -814,7 +814,7 @@ getSubscribeInfo(callback: AsyncCallback\): void ```ts //获取订阅者信息回调 function getCB(err:Base.BusinessError, subscribeInfo:CommonEventManager.CommonEventSubscribeInfo) { - if (err.code) { + if (err.code !== undefined && err.code != null) { console.error(`getSubscribeInfo failed, code is ${err.code}, message is ${err.message}`); } else { console.info("subscribeInfo " + JSON.stringify(subscribeInfo)); @@ -887,7 +887,7 @@ finishCommonEvent(callback: AsyncCallback\): void ```ts //结束当前有序公共事件的回调 function finishCB(err:Base.BusinessError) { - if (err.code) { + if (err.code !== undefined && err.code != null) { console.error(`finishCommonEvent failed, code is ${err.code}, message is ${err.message}`); } else { console.info("FinishCommonEvent");