From 90851d9b73b075e5dbe82dbbd0647e3c9fc2c432 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=B1=E5=A4=A9=E6=80=A1?= Date: Mon, 17 Oct 2022 05:06:13 +0000 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 朱天怡 --- .../apis/js-apis-backgroundTaskManager.md | 13 +- .../reference/apis/js-apis-workScheduler.md | 149 ++++++++++-------- .../errorcodes/errorcode-backgroundTaskMgr.md | 4 +- .../errorcodes/errorcode-workScheduler.md | 4 +- 4 files changed, 103 insertions(+), 67 deletions(-) diff --git a/zh-cn/application-dev/reference/apis/js-apis-backgroundTaskManager.md b/zh-cn/application-dev/reference/apis/js-apis-backgroundTaskManager.md index eacc955069..1a2c040d1e 100644 --- a/zh-cn/application-dev/reference/apis/js-apis-backgroundTaskManager.md +++ b/zh-cn/application-dev/reference/apis/js-apis-backgroundTaskManager.md @@ -13,6 +13,13 @@ > **说明:** > 本模块首批接口从API version 7开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 +## 导入模块 + +```js +import backgroundTaskManager from '@ohos.backgroundTaskManager'; +``` +## backgroundTaskManager.requestSuspendDelay + ## 导入模块 @@ -21,7 +28,7 @@ import backgroundTaskManager from '@ohos.backgroundTaskManager'; ``` -## backgroundTaskManager.requestSuspendDelay +## backgroundTaskManager.requestSuspendDelay(deprecated) requestSuspendDelay(reason: string, callback: Callback<void>): DelaySuspendInfo @@ -29,6 +36,10 @@ requestSuspendDelay(reason: string, callback: Callback<void>): DelaySuspen 延迟挂起时间一般情况下默认值为180000,低电量(依据系统低电量广播)时默认值为60000。 +> **说明:** 从API version 9开始废弃,建议使用[backgroundTaskManager.requestSuspendDelay](#reminderagentmanagerpublishreminder9) +> +> 从 API version 7开始支持。 + **系统能力:** SystemCapability.ResourceSchedule.BackgroundTaskManager.TransientTask **参数**: diff --git a/zh-cn/application-dev/reference/apis/js-apis-workScheduler.md b/zh-cn/application-dev/reference/apis/js-apis-workScheduler.md index a448708469..186fd9383e 100644 --- a/zh-cn/application-dev/reference/apis/js-apis-workScheduler.md +++ b/zh-cn/application-dev/reference/apis/js-apis-workScheduler.md @@ -9,6 +9,7 @@ > - 本模块首批接口从API version 9开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 > - 本模块接口仅可在Stage模型下使用。 > - 延迟任务调度约束见[延迟任务调度概述](../../task-management/work-scheduler-overview.md)。 +> - 延迟任务调度错误码见[延迟任务错误码](../errorcodes/errorcode-workScheduler.md)。 ## 导入模块 @@ -18,7 +19,7 @@ import workScheduler from '@ohos.workScheduler'; ``` ## workScheduler.startWork -startWork(work: WorkInfo): boolean +startWork(work: WorkInfo): void 通知WorkSchedulerService将工作添加到执行队列。 @@ -30,12 +31,6 @@ startWork(work: WorkInfo): boolean | ---- | --------------------- | ---- | -------------- | | work | [WorkInfo](#workinfo) | 是 | 指示要添加到执行队列的工作。 | -**返回值**: - -| 类型 | 说明 | -| ------- | -------------------------------- | -| boolean | 如果工作成功添加到执行队列,则返回true,否则返回false。 | - **示例**: ```js @@ -53,12 +48,16 @@ startWork(work: WorkInfo): boolean mykey3: 1.5 } } - var res = workScheduler.startWork(workInfo); - console.info(`workschedulerLog res: ${res}`); + try{ + workScheduler.startWork(workInfo); + console.info('workschedulerLog startWork success'); + } catch (error) { + console.error(`workschedulerLog startwork failed. code is ${error.code} message is ${error.message}`); + } ``` ## workScheduler.stopWork -stopWork(work: WorkInfo, needCancel?: boolean): boolean +stopWork(work: WorkInfo, needCancel?: boolean): void 通知WorkSchedulerService停止指定工作。 @@ -71,12 +70,6 @@ stopWork(work: WorkInfo, needCancel?: boolean): boolean | work | [WorkInfo](#workinfo) | 是 | 指示要停止的工作。 | | needCancel | boolean | 是 | 是否需要取消的工作。 | -**返回值**: - -| 类型 | 说明 | -| ------- | ----------------------- | -| boolean | 如果成功,则返回true,否则返回false。 | - **示例**: ```js @@ -94,8 +87,12 @@ stopWork(work: WorkInfo, needCancel?: boolean): boolean mykey3: 1.5 } } - var res = workScheduler.stopWork(workInfo, false); - console.info(`workschedulerLog res: ${res}`); + try{ + workScheduler.stopWork(workInfo, false); + console.info('workschedulerLog stopWork success'); + } catch (error) { + console.error(`workschedulerLog stopWork failed. code is ${error.code} message is ${error.message}`); + } ``` ## workScheduler.getWorkStatus @@ -115,15 +112,19 @@ getWorkStatus(workId: number, callback : AsyncCallback\): void **示例**: ```js - workScheduler.getWorkStatus(50, (err, res) => { - if (err) { - console.info(`workschedulerLog getWorkStatus failed, because: ${err.code}`); - } else { - for (let item in res) { - console.info(`workschedulerLog getWorkStatus success, ${item} is: ${res[item]}`); + try{ + workScheduler.getWorkStatus(50, (error, res) => { + if (error) { + console.error(`workschedulerLog getWorkStatus failed. code is ${error.code} message is ${error.message}`); + } else { + for (let item in res) { + console.info(`workschedulerLog getWorkStatus success, ${item} is: ${res[item]}`); + } } - } - }); + }); + } catch (error) { + console.error(`workschedulerLog getWorkStatus failed. code is ${error.code} message is ${error.message}`); + } ``` ## workScheduler.getWorkStatus @@ -148,13 +149,17 @@ getWorkStatus(workId: number): Promise\ **示例**: ```js - workScheduler.getWorkStatus(50).then((res) => { - for (let item in res) { - console.info(`workschedulerLog getWorkStatus success, ${item} is: ${res[item]}`); - } - }).catch((err) => { - console.info(`workschedulerLog getWorkStatus failed, because: ${err.code}`); - }) + try{ + workScheduler.getWorkStatus(50).then((res) => { + for (let item in res) { + console.info(`workschedulerLog getWorkStatus success, ${item} is: ${res[item]}`); + } + }).catch((error) => { + console.error(`workschedulerLog getWorkStatus failed. code is ${error.code} message is ${error.message}`); + }) + } catch (error) { + console.error(`workschedulerLog getWorkStatus failed. code is ${error.code} message is ${error.message}`); + } ``` ## workScheduler.obtainAllWorks @@ -179,13 +184,17 @@ obtainAllWorks(callback : AsyncCallback\): Array\ **示例**: ```js - workScheduler.obtainAllWorks((err, res) =>{ - if (err) { - console.info(`workschedulerLog obtainAllWorks failed, because: ${err.code}`); - } else { - console.info(`workschedulerLog obtainAllWorks success, data is: ${JSON.stringify(res)}`); - } - }); + try{ + workScheduler.obtainAllWorks((error, res) =>{ + if (error) { + console.error(`workschedulerLog obtainAllWorks failed. code is ${error.code} message is ${error.message}`); + } else { + console.info(`workschedulerLog obtainAllWorks success, data is: ${JSON.stringify(res)}`); + } + }); + } catch (error) { + console.error(`workschedulerLog obtainAllWorks failed. code is ${error.code} message is ${error.message}`); + } ``` ## workScheduler.obtainAllWorks @@ -204,15 +213,19 @@ obtainAllWorks(): Promise> **示例**: ```js - workScheduler.obtainAllWorks().then((res) => { - console.info(`workschedulerLog obtainAllWorks success, data is: ${JSON.stringify(res)}`); - }).catch((err) => { - console.info(`workschedulerLog obtainAllWorks failed, because: ${err.code}`); - }) + try{ + workScheduler.obtainAllWorks().then((res) => { + console.info(`workschedulerLog obtainAllWorks success, data is: ${JSON.stringify(res)}`); + }).catch((error) => { + console.error(`workschedulerLog obtainAllWorks failed. code is ${error.code} message is ${error.message}`); + }) + } catch (error) { + console.error(`workschedulerLog obtainAllWorks failed. code is ${error.code} message is ${error.message}`); + } ``` ## workScheduler.stopAndClearWorks -stopAndClearWorks(): boolean +stopAndClearWorks(): void 停止和取消与当前应用程序关联的所有工作。 @@ -221,8 +234,12 @@ stopAndClearWorks(): boolean **示例**: ```js - let res = workScheduler.stopAndClearWorks(); - console.info(`workschedulerLog res: ${res}`); + try{ + workScheduler.stopAndClearWorks(); + console.info(`workschedulerLog stopAndClearWorks success`); + } catch (error) { + console.error(`workschedulerLog stopAndClearWorks failed. code is ${error.code} message is ${error.message}`); + } ``` ## workScheduler.isLastWorkTimeOut @@ -248,13 +265,17 @@ isLastWorkTimeOut(workId: number, callback : AsyncCallback\): boolean **示例**: ```js - workScheduler.isLastWorkTimeOut(500, (err, res) =>{ - if (err) { - console.info(`workschedulerLog isLastWorkTimeOut failed, because: ${err.code}`); - } else { - console.info(`workschedulerLog isLastWorkTimeOut success, data is: ${res}`); - } - }); + try{ + workScheduler.isLastWorkTimeOut(500, (error, res) =>{ + if (error) { + onsole.error(`workschedulerLog isLastWorkTimeOut failed. code is ${error.code} message is ${error.message}`); + } else { + console.info(`workschedulerLog isLastWorkTimeOut success, data is: ${res}`); + } + }); + } catch (error) { + console.error(`workschedulerLog isLastWorkTimeOut failed. code is ${error.code} message is ${error.message}`); + } ``` ## workScheduler.isLastWorkTimeOut @@ -279,13 +300,17 @@ isLastWorkTimeOut(workId: number): Promise\ **示例**: ```js - workScheduler.isLastWorkTimeOut(500) - .then(res => { - console.info(`workschedulerLog isLastWorkTimeOut success, data is: ${res}`); - }) - .catch(err => { - console.info(`workschedulerLog isLastWorkTimeOut failed, because: ${err.code}`); - }); + try{ + workScheduler.isLastWorkTimeOut(500) + .then(res => { + console.info(`workschedulerLog isLastWorkTimeOut success, data is: ${res}`); + }) + .catch(error => { + console.error(`workschedulerLog isLastWorkTimeOut failed. code is ${error.code} message is ${error.message}`); + }); + } catch (error) { + console.error(`workschedulerLog isLastWorkTimeOut failed. code is ${error.code} message is ${error.message}`); + } ``` ## WorkInfo diff --git a/zh-cn/application-dev/reference/errorcodes/errorcode-backgroundTaskMgr.md b/zh-cn/application-dev/reference/errorcodes/errorcode-backgroundTaskMgr.md index 7928ab4634..29a7e6b442 100644 --- a/zh-cn/application-dev/reference/errorcodes/errorcode-backgroundTaskMgr.md +++ b/zh-cn/application-dev/reference/errorcodes/errorcode-backgroundTaskMgr.md @@ -40,7 +40,7 @@ Memory operation failed. ## 9800002 Parcel读写操作失败 ### 错误信息 -The number of reminders exceeds the limit. +Parcel operation failed. ### 可能原因 1. 调用MessageParcel对象读取或写入对象异常 @@ -62,7 +62,7 @@ Inner transact failed. ## 9800004 系统服务失败 ### 错误信息 -Inner transact failed. +System service operation failed. ### 可能原因 1. 系统服务还未启动 diff --git a/zh-cn/application-dev/reference/errorcodes/errorcode-workScheduler.md b/zh-cn/application-dev/reference/errorcodes/errorcode-workScheduler.md index 59c6f654f2..961a3d603b 100644 --- a/zh-cn/application-dev/reference/errorcodes/errorcode-workScheduler.md +++ b/zh-cn/application-dev/reference/errorcodes/errorcode-workScheduler.md @@ -29,7 +29,7 @@ Memory operation failed. ## 9700002 Parcel读写操作失败 ### 错误信息 -The number of reminders exceeds the limit. +Parcel operation failed. ### 可能原因 1. 调用MessageParcel对象读取或写入对象异常 @@ -40,7 +40,7 @@ The number of reminders exceeds the limit. ## 9700003 系统服务失败 ### 错误信息 -Inner transact failed. +System service operation failed. ### 可能原因 1. 系统服务还未启动 -- GitLab