提交 e67918ce 编写于 作者: G guojin31

上传下载、输入法示例代码ArkTs规范整改

Signed-off-by: Nguojin31 <guojin31@huawei.com>
上级 74e05859
...@@ -43,7 +43,7 @@ destroy(callback: AsyncCallback\<void>): void ...@@ -43,7 +43,7 @@ destroy(callback: AsyncCallback\<void>): void
**示例:** **示例:**
```ts ```ts
this.context.destroy((err: Error) => { this.context.destroy((err: BusinessError) => {
if(err) { if(err) {
console.log('Failed to destroy context.'); console.log('Failed to destroy context.');
return; return;
...@@ -71,7 +71,7 @@ destroy(): Promise\<void>; ...@@ -71,7 +71,7 @@ destroy(): Promise\<void>;
```ts ```ts
this.context.destroy().then(() => { this.context.destroy().then(() => {
console.log('Succeed in destroying context.'); console.log('Succeed in destroying context.');
}).catch((err: Error)=>{ }).catch((err: BusinessError)=>{
console.log('Failed to destroy context.'); console.log('Failed to destroy context.');
}); });
``` ```
...@@ -128,7 +128,7 @@ switchInputMethod(target: InputMethodProperty, callback: AsyncCallback&lt;boolea ...@@ -128,7 +128,7 @@ switchInputMethod(target: InputMethodProperty, callback: AsyncCallback&lt;boolea
```ts ```ts
let currentIme = inputMethod.getCurrentInputMethod(); let currentIme = inputMethod.getCurrentInputMethod();
try{ try{
inputMethod.switchInputMethod(currentIme, (err: Error, result: boolean) => { inputMethod.switchInputMethod(currentIme, (err: BusinessError, result: boolean) => {
if (err) { if (err) {
console.error(`Failed to switchInputMethod: ${JSON.stringify(err)}`); console.error(`Failed to switchInputMethod: ${JSON.stringify(err)}`);
return; return;
...@@ -184,7 +184,7 @@ try { ...@@ -184,7 +184,7 @@ try {
} else { } else {
console.error('Failed to switchInputMethod.'); console.error('Failed to switchInputMethod.');
} }
}).catch((err: Error) => { }).catch((err: BusinessError) => {
console.error(`Failed to switchInputMethod: ${JSON.stringify(err)}`); console.error(`Failed to switchInputMethod: ${JSON.stringify(err)}`);
}) })
} catch (err) { } catch (err) {
...@@ -257,7 +257,7 @@ try { ...@@ -257,7 +257,7 @@ try {
icon: "", icon: "",
iconId: 0, iconId: 0,
extra: extra extra: extra
}, (err: Error, result: boolean) => { }, (err: BusinessError, result: boolean) => {
if (err) { if (err) {
console.error(`Failed to switchCurrentInputMethodSubtype: ${JSON.stringify(err)}`); console.error(`Failed to switchCurrentInputMethodSubtype: ${JSON.stringify(err)}`);
return; return;
...@@ -329,7 +329,7 @@ try { ...@@ -329,7 +329,7 @@ try {
} else { } else {
console.error('Failed to switchCurrentInputMethodSubtype.'); console.error('Failed to switchCurrentInputMethodSubtype.');
} }
}).catch((err: Error) => { }).catch((err: BusinessError) => {
console.error(`Failed to switchCurrentInputMethodSubtype: ${JSON.stringify(err)}`); console.error(`Failed to switchCurrentInputMethodSubtype: ${JSON.stringify(err)}`);
}) })
} catch(err) { } catch(err) {
...@@ -390,7 +390,7 @@ switchCurrentInputMethodAndSubtype(inputMethodProperty: InputMethodProperty, inp ...@@ -390,7 +390,7 @@ switchCurrentInputMethodAndSubtype(inputMethodProperty: InputMethodProperty, inp
let currentIme = inputMethod.getCurrentInputMethod(); let currentIme = inputMethod.getCurrentInputMethod();
let imSubType = inputMethod.getCurrentInputMethodSubtype(); let imSubType = inputMethod.getCurrentInputMethodSubtype();
try { try {
inputMethod.switchCurrentInputMethodAndSubtype(currentIme, imSubType, (err: Error, result: boolean) => { inputMethod.switchCurrentInputMethodAndSubtype(currentIme, imSubType, (err: BusinessError, result: boolean) => {
if (err) { if (err) {
console.error(`Failed to switchCurrentInputMethodAndSubtype: ${JSON.stringify(err)}`); console.error(`Failed to switchCurrentInputMethodAndSubtype: ${JSON.stringify(err)}`);
return; return;
...@@ -450,7 +450,7 @@ try { ...@@ -450,7 +450,7 @@ try {
} else { } else {
console.error('Failed to switchCurrentInputMethodAndSubtype.'); console.error('Failed to switchCurrentInputMethodAndSubtype.');
} }
}).catch((err: Error) => { }).catch((err: BusinessError) => {
console.error(`Failed to switchCurrentInputMethodAndSubtype: ${JSON.stringify(err)}`); console.error(`Failed to switchCurrentInputMethodAndSubtype: ${JSON.stringify(err)}`);
}) })
} catch(err) { } catch(err) {
...@@ -704,7 +704,7 @@ try { ...@@ -704,7 +704,7 @@ try {
enterKeyType: 1 enterKeyType: 1
} }
}; };
inputMethodController.attach(true, textConfig, (err: Error) => { inputMethodController.attach(true, textConfig, (err: BusinessError) => {
if (err) { if (err) {
console.error(`Failed to attach: ${JSON.stringify(err)}`); console.error(`Failed to attach: ${JSON.stringify(err)}`);
return; return;
...@@ -762,7 +762,7 @@ try { ...@@ -762,7 +762,7 @@ try {
}; };
inputMethodController.attach(true, textConfig).then(() => { inputMethodController.attach(true, textConfig).then(() => {
console.log('Succeeded in attaching inputMethod.'); console.log('Succeeded in attaching inputMethod.');
}).catch((err: Error) => { }).catch((err: BusinessError) => {
console.error(`Failed to attach: ${JSON.stringify(err)}`); console.error(`Failed to attach: ${JSON.stringify(err)}`);
}) })
} catch(err) { } catch(err) {
...@@ -801,7 +801,7 @@ showTextInput(callback: AsyncCallback&lt;void&gt;): void ...@@ -801,7 +801,7 @@ showTextInput(callback: AsyncCallback&lt;void&gt;): void
**示例:** **示例:**
```ts ```ts
inputMethodController.showTextInput((err: Error) => { inputMethodController.showTextInput((err: BusinessError) => {
if (err) { if (err) {
console.error(`Failed to showTextInput: ${JSON.stringify(err)}`); console.error(`Failed to showTextInput: ${JSON.stringify(err)}`);
return; return;
...@@ -843,7 +843,7 @@ showTextInput(): Promise&lt;void&gt; ...@@ -843,7 +843,7 @@ showTextInput(): Promise&lt;void&gt;
```ts ```ts
inputMethodController.showTextInput().then(() => { inputMethodController.showTextInput().then(() => {
console.log('Succeeded in showing text input.'); console.log('Succeeded in showing text input.');
}).catch((err: Error) => { }).catch((err: BusinessError) => {
console.error(`Failed to showTextInput: ${JSON.stringify(err)}`); console.error(`Failed to showTextInput: ${JSON.stringify(err)}`);
}); });
``` ```
...@@ -881,7 +881,7 @@ hideTextInput(callback: AsyncCallback&lt;void&gt;): void ...@@ -881,7 +881,7 @@ hideTextInput(callback: AsyncCallback&lt;void&gt;): void
**示例:** **示例:**
```ts ```ts
inputMethodController.hideTextInput((err: Error) => { inputMethodController.hideTextInput((err: BusinessError) => {
if (err) { if (err) {
console.error(`Failed to hideTextInput: ${JSON.stringify(err)}`); console.error(`Failed to hideTextInput: ${JSON.stringify(err)}`);
return; return;
...@@ -925,7 +925,7 @@ hideTextInput(): Promise&lt;void&gt; ...@@ -925,7 +925,7 @@ hideTextInput(): Promise&lt;void&gt;
```ts ```ts
inputMethodController.hideTextInput().then(() => { inputMethodController.hideTextInput().then(() => {
console.log('Succeeded in hiding inputMethod.'); console.log('Succeeded in hiding inputMethod.');
}).catch((err: Error) => { }).catch((err: BusinessError) => {
console.error(`Failed to hideTextInput: ${JSON.stringify(err)}`); console.error(`Failed to hideTextInput: ${JSON.stringify(err)}`);
}) })
``` ```
...@@ -956,7 +956,7 @@ detach(callback: AsyncCallback&lt;void&gt;): void ...@@ -956,7 +956,7 @@ detach(callback: AsyncCallback&lt;void&gt;): void
**示例:** **示例:**
```ts ```ts
inputMethodController.detach((err: Error) => { inputMethodController.detach((err: BusinessError) => {
if (err) { if (err) {
console.error(`Failed to detach: ${JSON.stringify(err)}`); console.error(`Failed to detach: ${JSON.stringify(err)}`);
return; return;
...@@ -993,7 +993,7 @@ detach(): Promise&lt;void&gt; ...@@ -993,7 +993,7 @@ detach(): Promise&lt;void&gt;
```ts ```ts
inputMethodController.detach().then(() => { inputMethodController.detach().then(() => {
console.log('Succeeded in detaching inputMethod.'); console.log('Succeeded in detaching inputMethod.');
}).catch((err: Error) => { }).catch((err: BusinessError) => {
console.error(`Failed to detach: ${JSON.stringify(err)}`); console.error(`Failed to detach: ${JSON.stringify(err)}`);
}); });
``` ```
...@@ -1032,7 +1032,7 @@ setCallingWindow(windowId: number, callback: AsyncCallback&lt;void&gt;): void ...@@ -1032,7 +1032,7 @@ setCallingWindow(windowId: number, callback: AsyncCallback&lt;void&gt;): void
```ts ```ts
try { try {
let windowId: number = 2000; let windowId: number = 2000;
inputMethodController.setCallingWindow(windowId, (err: Error) => { inputMethodController.setCallingWindow(windowId, (err: BusinessError) => {
if (err) { if (err) {
console.error(`Failed to setCallingWindow: ${JSON.stringify(err)}`); console.error(`Failed to setCallingWindow: ${JSON.stringify(err)}`);
return; return;
...@@ -1085,7 +1085,7 @@ try { ...@@ -1085,7 +1085,7 @@ try {
let windowId: number = 2000; let windowId: number = 2000;
inputMethodController.setCallingWindow(windowId).then(() => { inputMethodController.setCallingWindow(windowId).then(() => {
console.log('Succeeded in setting callingWindow.'); console.log('Succeeded in setting callingWindow.');
}).catch((err: Error) => { }).catch((err: BusinessError) => {
console.error(`Failed to setCallingWindow: ${JSON.stringify(err)}`); console.error(`Failed to setCallingWindow: ${JSON.stringify(err)}`);
}) })
} catch(err) { } catch(err) {
...@@ -1123,7 +1123,7 @@ updateCursor(cursorInfo: CursorInfo, callback: AsyncCallback&lt;void&gt;): void ...@@ -1123,7 +1123,7 @@ updateCursor(cursorInfo: CursorInfo, callback: AsyncCallback&lt;void&gt;): void
```ts ```ts
try { try {
let cursorInfo: inputMethod.CursorInfo = { left: 0, top: 0, width: 600, height: 800 }; let cursorInfo: inputMethod.CursorInfo = { left: 0, top: 0, width: 600, height: 800 };
inputMethodController.updateCursor(cursorInfo, (err: Error) => { inputMethodController.updateCursor(cursorInfo, (err: BusinessError) => {
if (err) { if (err) {
console.error(`Failed to updateCursor: ${JSON.stringify(err)}`); console.error(`Failed to updateCursor: ${JSON.stringify(err)}`);
return; return;
...@@ -1172,7 +1172,7 @@ try { ...@@ -1172,7 +1172,7 @@ try {
let cursorInfo: inputMethod.CursorInfo = { left: 0, top: 0, width: 600, height: 800 }; let cursorInfo: inputMethod.CursorInfo = { left: 0, top: 0, width: 600, height: 800 };
inputMethodController.updateCursor(cursorInfo).then(() => { inputMethodController.updateCursor(cursorInfo).then(() => {
console.log('Succeeded in updating cursorInfo.'); console.log('Succeeded in updating cursorInfo.');
}).catch((err: Error) => { }).catch((err: BusinessError) => {
console.error(`Failed to updateCursor: ${JSON.stringify(err)}`); console.error(`Failed to updateCursor: ${JSON.stringify(err)}`);
}) })
} catch(err) { } catch(err) {
...@@ -1211,7 +1211,7 @@ changeSelection(text: string, start: number, end: number, callback: AsyncCallbac ...@@ -1211,7 +1211,7 @@ changeSelection(text: string, start: number, end: number, callback: AsyncCallbac
```ts ```ts
try { try {
inputMethodController.changeSelection('text', 0, 5, (err: Error) => { inputMethodController.changeSelection('text', 0, 5, (err: BusinessError) => {
if (err) { if (err) {
console.error(`Failed to changeSelection: ${JSON.stringify(err)}`); console.error(`Failed to changeSelection: ${JSON.stringify(err)}`);
return; return;
...@@ -1261,7 +1261,7 @@ changeSelection(text: string, start: number, end: number): Promise&lt;void&gt; ...@@ -1261,7 +1261,7 @@ changeSelection(text: string, start: number, end: number): Promise&lt;void&gt;
try { try {
inputMethodController.changeSelection('test', 0, 5).then(() => { inputMethodController.changeSelection('test', 0, 5).then(() => {
console.log('Succeeded in changing selection.'); console.log('Succeeded in changing selection.');
}).catch((err: Error) => { }).catch((err: BusinessError) => {
console.error(`Failed to changeSelection: ${JSON.stringify(err)}`); console.error(`Failed to changeSelection: ${JSON.stringify(err)}`);
}) })
} catch(err) { } catch(err) {
...@@ -1299,7 +1299,7 @@ updateAttribute(attribute: InputAttribute, callback: AsyncCallback&lt;void&gt;): ...@@ -1299,7 +1299,7 @@ updateAttribute(attribute: InputAttribute, callback: AsyncCallback&lt;void&gt;):
```ts ```ts
try { try {
let inputAttribute: inputMethod.InputAttribute = { textInputType: 0, enterKeyType: 1 }; let inputAttribute: inputMethod.InputAttribute = { textInputType: 0, enterKeyType: 1 };
inputMethodController.updateAttribute(inputAttribute, (err: Error) => { inputMethodController.updateAttribute(inputAttribute, (err: BusinessError) => {
if (err) { if (err) {
console.error(`Failed to updateAttribute: ${JSON.stringify(err)}`); console.error(`Failed to updateAttribute: ${JSON.stringify(err)}`);
return; return;
...@@ -1348,7 +1348,7 @@ try { ...@@ -1348,7 +1348,7 @@ try {
let inputAttribute: inputMethod.InputAttribute = { textInputType: 0, enterKeyType: 1 }; let inputAttribute: inputMethod.InputAttribute = { textInputType: 0, enterKeyType: 1 };
inputMethodController.updateAttribute(inputAttribute).then(() => { inputMethodController.updateAttribute(inputAttribute).then(() => {
console.log('Succeeded in updating attribute.'); console.log('Succeeded in updating attribute.');
}).catch((err: Error) => { }).catch((err: BusinessError) => {
console.error(`Failed to updateAttribute: ${JSON.stringify(err)}`); console.error(`Failed to updateAttribute: ${JSON.stringify(err)}`);
}) })
} catch(err) { } catch(err) {
...@@ -1387,7 +1387,7 @@ stopInputSession(callback: AsyncCallback&lt;boolean&gt;): void ...@@ -1387,7 +1387,7 @@ stopInputSession(callback: AsyncCallback&lt;boolean&gt;): void
```ts ```ts
try { try {
inputMethodController.stopInputSession((err: Error, result: boolean) => { inputMethodController.stopInputSession((err: BusinessError, result: boolean) => {
if (err) { if (err) {
console.error(`Failed to stopInputSession: ${JSON.stringify(err)}`); console.error(`Failed to stopInputSession: ${JSON.stringify(err)}`);
return; return;
...@@ -1440,7 +1440,7 @@ try { ...@@ -1440,7 +1440,7 @@ try {
} else { } else {
console.error('Failed to stopInputSession.'); console.error('Failed to stopInputSession.');
} }
}).catch((err: Error) => { }).catch((err: BusinessError) => {
console.error(`Failed to stopInputSession: ${JSON.stringify(err)}`); console.error(`Failed to stopInputSession: ${JSON.stringify(err)}`);
}) })
} catch(err) { } catch(err) {
...@@ -1480,7 +1480,7 @@ showSoftKeyboard(callback: AsyncCallback&lt;void&gt;): void ...@@ -1480,7 +1480,7 @@ showSoftKeyboard(callback: AsyncCallback&lt;void&gt;): void
**示例:** **示例:**
```ts ```ts
inputMethodController.showSoftKeyboard((err: Error) => { inputMethodController.showSoftKeyboard((err: BusinessError) => {
if (!err) { if (!err) {
console.log('Succeeded in showing softKeyboard.'); console.log('Succeeded in showing softKeyboard.');
} else { } else {
...@@ -1523,7 +1523,7 @@ showSoftKeyboard(): Promise&lt;void&gt; ...@@ -1523,7 +1523,7 @@ showSoftKeyboard(): Promise&lt;void&gt;
```ts ```ts
inputMethodController.showSoftKeyboard().then(() => { inputMethodController.showSoftKeyboard().then(() => {
console.log('Succeeded in showing softKeyboard.'); console.log('Succeeded in showing softKeyboard.');
}).catch((err: Error) => { }).catch((err: BusinessError) => {
console.error(`Failed to show softKeyboard: ${JSON.stringify(err)}`); console.error(`Failed to show softKeyboard: ${JSON.stringify(err)}`);
}); });
``` ```
...@@ -1560,7 +1560,7 @@ hideSoftKeyboard(callback: AsyncCallback&lt;void&gt;): void ...@@ -1560,7 +1560,7 @@ hideSoftKeyboard(callback: AsyncCallback&lt;void&gt;): void
**示例:** **示例:**
```ts ```ts
inputMethodController.hideSoftKeyboard((err: Error) => { inputMethodController.hideSoftKeyboard((err: BusinessError) => {
if (!err) { if (!err) {
console.log('Succeeded in hiding softKeyboard.'); console.log('Succeeded in hiding softKeyboard.');
} else { } else {
...@@ -1603,7 +1603,7 @@ hideSoftKeyboard(): Promise&lt;void&gt; ...@@ -1603,7 +1603,7 @@ hideSoftKeyboard(): Promise&lt;void&gt;
```ts ```ts
inputMethodController.hideSoftKeyboard().then(() => { inputMethodController.hideSoftKeyboard().then(() => {
console.log('Succeeded in hiding softKeyboard.'); console.log('Succeeded in hiding softKeyboard.');
}).catch((err: Error) => { }).catch((err: BusinessError) => {
console.error(`Failed to hide softKeyboard: ${JSON.stringify(err)}`); console.error(`Failed to hide softKeyboard: ${JSON.stringify(err)}`);
}); });
``` ```
...@@ -1631,7 +1631,7 @@ stopInput(callback: AsyncCallback&lt;boolean&gt;): void ...@@ -1631,7 +1631,7 @@ stopInput(callback: AsyncCallback&lt;boolean&gt;): void
**示例:** **示例:**
```ts ```ts
inputMethodController.stopInput((err: Error, result: boolean) => { inputMethodController.stopInput((err: BusinessError, result: boolean) => {
if (err) { if (err) {
console.error(`Failed to stopInput: ${JSON.stringify(err)}`); console.error(`Failed to stopInput: ${JSON.stringify(err)}`);
return; return;
...@@ -1673,7 +1673,7 @@ inputMethodController.stopInput().then((result: boolean) => { ...@@ -1673,7 +1673,7 @@ inputMethodController.stopInput().then((result: boolean) => {
} else { } else {
console.error('Failed to stopInput.'); console.error('Failed to stopInput.');
} }
}).catch((err: Error) => { }).catch((err: BusinessError) => {
console.error(`Failed to stopInput: ${JSON.stringify(err)}`); console.error(`Failed to stopInput: ${JSON.stringify(err)}`);
}) })
``` ```
...@@ -2577,7 +2577,7 @@ let inputMethodProperty: inputMethod.InputMethodProperty = { ...@@ -2577,7 +2577,7 @@ let inputMethodProperty: inputMethod.InputMethodProperty = {
id: 'propertyId', id: 'propertyId',
} }
try { try {
inputMethodSetting.listInputMethodSubtype(inputMethodProperty, (err: Error, data: Array<InputMethodSubtype>) => { inputMethodSetting.listInputMethodSubtype(inputMethodProperty, (err: BusinessError, data: Array<InputMethodSubtype>) => {
if (err) { if (err) {
console.error(`Failed to listInputMethodSubtype: ${JSON.stringify(err)}`); console.error(`Failed to listInputMethodSubtype: ${JSON.stringify(err)}`);
return; return;
...@@ -2665,7 +2665,7 @@ listCurrentInputMethodSubtype(callback: AsyncCallback&lt;Array&lt;InputMethodSub ...@@ -2665,7 +2665,7 @@ listCurrentInputMethodSubtype(callback: AsyncCallback&lt;Array&lt;InputMethodSub
```ts ```ts
try { try {
inputMethodSetting.listCurrentInputMethodSubtype((err: Error, data: Array<InputMethodSubtype>) => { inputMethodSetting.listCurrentInputMethodSubtype((err: BusinessError, data: Array<InputMethodSubtype>) => {
if (err) { if (err) {
console.error(`Failed to listCurrentInputMethodSubtype: ${JSON.stringify(err)}`); console.error(`Failed to listCurrentInputMethodSubtype: ${JSON.stringify(err)}`);
return; return;
...@@ -2748,7 +2748,7 @@ getInputMethods(enable: boolean, callback: AsyncCallback&lt;Array&lt;InputMethod ...@@ -2748,7 +2748,7 @@ getInputMethods(enable: boolean, callback: AsyncCallback&lt;Array&lt;InputMethod
```ts ```ts
try { try {
inputMethodSetting.getInputMethods(true, (err: Error, data: Array<inputMethod.InputMethodProperty>) => { inputMethodSetting.getInputMethods(true, (err: BusinessError, data: Array<inputMethod.InputMethodProperty>) => {
if (err) { if (err) {
console.error(`Failed to getInputMethods: ${JSON.stringify(err)}`); console.error(`Failed to getInputMethods: ${JSON.stringify(err)}`);
return; return;
...@@ -2835,7 +2835,7 @@ showOptionalInputMethods(callback: AsyncCallback&lt;boolean&gt;): void ...@@ -2835,7 +2835,7 @@ showOptionalInputMethods(callback: AsyncCallback&lt;boolean&gt;): void
```ts ```ts
try { try {
inputMethodSetting.showOptionalInputMethods((err: Error, data: boolean) => { inputMethodSetting.showOptionalInputMethods((err: BusinessError, data: boolean) => {
if (err) { if (err) {
console.error(`Failed to showOptionalInputMethods: ${JSON.stringify(err)}`); console.error(`Failed to showOptionalInputMethods: ${JSON.stringify(err)}`);
return; return;
...@@ -2900,7 +2900,7 @@ listInputMethod(callback: AsyncCallback&lt;Array&lt;InputMethodProperty&gt;&gt;) ...@@ -2900,7 +2900,7 @@ listInputMethod(callback: AsyncCallback&lt;Array&lt;InputMethodProperty&gt;&gt;)
**示例:** **示例:**
```ts ```ts
inputMethodSetting.listInputMethod((err: Error, data: Array<inputMethod.InputMethodProperty>) => { inputMethodSetting.listInputMethod((err: BusinessError, data: Array<inputMethod.InputMethodProperty>) => {
if (err) { if (err) {
console.error(`Failed to listInputMethod: ${JSON.stringify(err)}`); console.error(`Failed to listInputMethod: ${JSON.stringify(err)}`);
return; return;
...@@ -2958,7 +2958,7 @@ displayOptionalInputMethod(callback: AsyncCallback&lt;void&gt;): void ...@@ -2958,7 +2958,7 @@ displayOptionalInputMethod(callback: AsyncCallback&lt;void&gt;): void
**示例:** **示例:**
```ts ```ts
inputMethodSetting.displayOptionalInputMethod((err: Error) => { inputMethodSetting.displayOptionalInputMethod((err: BusinessError) => {
if (err) { if (err) {
console.error(`Failed to displayOptionalInputMethod: ${JSON.stringify(err)}`); console.error(`Failed to displayOptionalInputMethod: ${JSON.stringify(err)}`);
return; return;
......
...@@ -512,7 +512,7 @@ let panelInfo: inputMethodEngine.PanelInfo = { ...@@ -512,7 +512,7 @@ let panelInfo: inputMethodEngine.PanelInfo = {
} }
try { try {
inputMethodEngine.getInputMethodAbility() inputMethodEngine.getInputMethodAbility()
.createPanel(this.context, panelInfo, (err: Error, panel: inputMethodEngine.Panel) => { .createPanel(this.context, panelInfo, (err: BusinessError, panel: inputMethodEngine.Panel) => {
if (err) { if (err) {
console.error(`Failed to createPanel: ${JSON.stringify(err)}`); console.error(`Failed to createPanel: ${JSON.stringify(err)}`);
return; return;
...@@ -560,7 +560,7 @@ let panelInfo: inputMethodEngine.PanelInfo = { ...@@ -560,7 +560,7 @@ let panelInfo: inputMethodEngine.PanelInfo = {
inputMethodEngine.getInputMethodAbility().createPanel(this.context, panelInfo) inputMethodEngine.getInputMethodAbility().createPanel(this.context, panelInfo)
.then((panel: inputMethodEngine.Panel) => { .then((panel: inputMethodEngine.Panel) => {
console.log('Succeed in creating panel.'); console.log('Succeed in creating panel.');
}).catch((err: Error) => { }).catch((err: BusinessError) => {
console.error(`Failed to create panel: ${JSON.stringify(err)}`); console.error(`Failed to create panel: ${JSON.stringify(err)}`);
}) })
``` ```
...@@ -590,7 +590,7 @@ let panelInfo: inputMethodEngine.PanelInfo = { ...@@ -590,7 +590,7 @@ let panelInfo: inputMethodEngine.PanelInfo = {
let inputPanel: inputMethodEngine.Panel | undefined = undefined; let inputPanel: inputMethodEngine.Panel | undefined = undefined;
try { try {
inputMethodEngine.getInputMethodAbility() inputMethodEngine.getInputMethodAbility()
.createPanel(this.context, panelInfo, (err: Error, panel: inputMethodEngine.Panel) => { .createPanel(this.context, panelInfo, (err: BusinessError, panel: inputMethodEngine.Panel) => {
if (err) { if (err) {
console.error(`Failed to create panel: ${JSON.stringify(err)}`); console.error(`Failed to create panel: ${JSON.stringify(err)}`);
return; return;
...@@ -603,7 +603,7 @@ try { ...@@ -603,7 +603,7 @@ try {
} }
try { try {
if (inputPanel) { if (inputPanel) {
inputMethodEngine.getInputMethodAbility().destroyPanel(inputPanel, (err: Error) => { inputMethodEngine.getInputMethodAbility().destroyPanel(inputPanel, (err: BusinessError) => {
if (err !== undefined) { if (err !== undefined) {
console.error(`Failed to destroy panel: ${JSON.stringify(err)}`); console.error(`Failed to destroy panel: ${JSON.stringify(err)}`);
return; return;
...@@ -645,7 +645,7 @@ let panelInfo: inputMethodEngine.PanelInfo = { ...@@ -645,7 +645,7 @@ let panelInfo: inputMethodEngine.PanelInfo = {
let inputPanel: inputMethodEngine.Panel | undefined = undefined; let inputPanel: inputMethodEngine.Panel | undefined = undefined;
try { try {
inputMethodEngine.getInputMethodAbility() inputMethodEngine.getInputMethodAbility()
.createPanel(this.context, panelInfo, (err: Error, panel: inputMethodEngine.Panel) => { .createPanel(this.context, panelInfo, (err: BusinessError, panel: inputMethodEngine.Panel) => {
if (err) { if (err) {
console.error(`Failed to create panel: ${JSON.stringify(err)}`); console.error(`Failed to create panel: ${JSON.stringify(err)}`);
return; return;
...@@ -661,7 +661,7 @@ try { ...@@ -661,7 +661,7 @@ try {
if (inputPanel) { if (inputPanel) {
inputMethodEngine.getInputMethodAbility().destroyPanel(inputPanel).then(() => { inputMethodEngine.getInputMethodAbility().destroyPanel(inputPanel).then(() => {
console.log('Succeed in destroying panel.'); console.log('Succeed in destroying panel.');
}).catch((err: Error) => { }).catch((err: BusinessError) => {
console.error(`Failed to destroy panel: ${JSON.stringify(err)}`); console.error(`Failed to destroy panel: ${JSON.stringify(err)}`);
}); });
} }
...@@ -996,7 +996,7 @@ setUiContent(path: string, callback: AsyncCallback\<void>): void ...@@ -996,7 +996,7 @@ setUiContent(path: string, callback: AsyncCallback\<void>): void
```ts ```ts
try { try {
panel.setUiContent('pages/page2/page2', (err: Error) => { panel.setUiContent('pages/page2/page2', (err: BusinessError) => {
if (err) { if (err) {
console.error(`Failed to setUiContent: ${JSON.stringify(err)}`); console.error(`Failed to setUiContent: ${JSON.stringify(err)}`);
return; return;
...@@ -1034,7 +1034,7 @@ setUiContent(path: string): Promise\<void> ...@@ -1034,7 +1034,7 @@ setUiContent(path: string): Promise\<void>
try { try {
panel.setUiContent('pages/page2/page2').then(() => { panel.setUiContent('pages/page2/page2').then(() => {
console.log('Succeeded in setting the content.'); console.log('Succeeded in setting the content.');
}).catch((err: Error) => { }).catch((err: BusinessError) => {
console.error(`Failed to setUiContent: ${JSON.stringify(err)}`); console.error(`Failed to setUiContent: ${JSON.stringify(err)}`);
}); });
} catch (err) { } catch (err) {
...@@ -1064,7 +1064,7 @@ setUiContent(path: string, storage: LocalStorage, callback: AsyncCallback\<void> ...@@ -1064,7 +1064,7 @@ setUiContent(path: string, storage: LocalStorage, callback: AsyncCallback\<void>
let storage = new LocalStorage(); let storage = new LocalStorage();
storage.setOrCreate('storageSimpleProp',121); storage.setOrCreate('storageSimpleProp',121);
try { try {
panel.setUiContent('pages/page2/page2', storage, (err: Error) => { panel.setUiContent('pages/page2/page2', storage, (err: BusinessError) => {
if (err) { if (err) {
console.error(`Failed to setUiContent: ${JSON.stringify(err)}`); console.error(`Failed to setUiContent: ${JSON.stringify(err)}`);
return; return;
...@@ -1105,7 +1105,7 @@ storage.setOrCreate('storageSimpleProp',121); ...@@ -1105,7 +1105,7 @@ storage.setOrCreate('storageSimpleProp',121);
try { try {
panel.setUiContent('pages/page2/page2')then(() => { panel.setUiContent('pages/page2/page2')then(() => {
console.log('Succeeded in setting the content.'); console.log('Succeeded in setting the content.');
}).catch((err: Error) => { }).catch((err: BusinessError) => {
console.error(`Failed to setUiContent: ${JSON.stringify(err)}`); console.error(`Failed to setUiContent: ${JSON.stringify(err)}`);
}); });
} catch (err) { } catch (err) {
...@@ -1137,7 +1137,7 @@ resize(width: number, height: number, callback: AsyncCallback\<void>): void ...@@ -1137,7 +1137,7 @@ resize(width: number, height: number, callback: AsyncCallback\<void>): void
```ts ```ts
try { try {
panel.resize(500, 1000, (err: Error) => { panel.resize(500, 1000, (err: BusinessError) => {
if (err) { if (err) {
console.error(`Failed to resize panel: ${JSON.stringify(err)}`); console.error(`Failed to resize panel: ${JSON.stringify(err)}`);
return; return;
...@@ -1180,7 +1180,7 @@ resize(width: number, height: number): Promise\<void>; ...@@ -1180,7 +1180,7 @@ resize(width: number, height: number): Promise\<void>;
try { try {
panel.resize(500, 1000).then(() => { panel.resize(500, 1000).then(() => {
console.log('Succeeded in changing the panel size.'); console.log('Succeeded in changing the panel size.');
}).catch((err: Error) => { }).catch((err: BusinessError) => {
console.error(`Failed to resize panel: ${JSON.stringify(err)}`); console.error(`Failed to resize panel: ${JSON.stringify(err)}`);
}); });
} catch (err) { } catch (err) {
...@@ -1208,7 +1208,7 @@ moveTo(x: number, y: number, callback: AsyncCallback\<void>): void ...@@ -1208,7 +1208,7 @@ moveTo(x: number, y: number, callback: AsyncCallback\<void>): void
```ts ```ts
try { try {
panel.moveTo(300, 300, (err: Error) =>{ panel.moveTo(300, 300, (err: BusinessError) =>{
if (err) { if (err) {
console.error(`Failed to move panel: ${JSON.stringify(err)}`); console.error(`Failed to move panel: ${JSON.stringify(err)}`);
return; return;
...@@ -1247,7 +1247,7 @@ moveTo(x: number, y: number): Promise\<void> ...@@ -1247,7 +1247,7 @@ moveTo(x: number, y: number): Promise\<void>
try { try {
panel.moveTo(300, 300).then(() => { panel.moveTo(300, 300).then(() => {
console.log('Succeeded in moving the panel.'); console.log('Succeeded in moving the panel.');
}).catch((err: Error) => { }).catch((err: BusinessError) => {
console.error(`Failed to move panel: ${JSON.stringify(err)}`); console.error(`Failed to move panel: ${JSON.stringify(err)}`);
}); });
} catch (err) { } catch (err) {
...@@ -1272,7 +1272,7 @@ show(callback: AsyncCallback\<void>): void ...@@ -1272,7 +1272,7 @@ show(callback: AsyncCallback\<void>): void
**示例:** **示例:**
```ts ```ts
panel.show((err: Error) => { panel.show((err: BusinessError) => {
if (err) { if (err) {
console.error(`Failed to show panel: ${JSON.stringify(err)}`); console.error(`Failed to show panel: ${JSON.stringify(err)}`);
return; return;
...@@ -1300,7 +1300,7 @@ show(): Promise\<void> ...@@ -1300,7 +1300,7 @@ show(): Promise\<void>
```ts ```ts
panel.show().then(() => { panel.show().then(() => {
console.log('Succeeded in showing the panel.'); console.log('Succeeded in showing the panel.');
}).catch((err: Error) => { }).catch((err: BusinessError) => {
console.error(`Failed to show panel: ${JSON.stringify(err)}`); console.error(`Failed to show panel: ${JSON.stringify(err)}`);
}); });
``` ```
...@@ -1322,7 +1322,7 @@ hide(callback: AsyncCallback\<void>): void ...@@ -1322,7 +1322,7 @@ hide(callback: AsyncCallback\<void>): void
**示例:** **示例:**
```ts ```ts
panel.hide((err: Error) => { panel.hide((err: BusinessError) => {
if (err) { if (err) {
console.error(`Failed to hide panel: ${JSON.stringify(err)}`); console.error(`Failed to hide panel: ${JSON.stringify(err)}`);
return; return;
...@@ -1350,7 +1350,7 @@ hide(): Promise\<void> ...@@ -1350,7 +1350,7 @@ hide(): Promise\<void>
```ts ```ts
panel.hide().then(() => { panel.hide().then(() => {
console.log('Succeeded in hiding the panel.'); console.log('Succeeded in hiding the panel.');
}).catch((err: Error) => { }).catch((err: BusinessError) => {
console.error(`Failed to hide panel: ${JSON.stringify(err)}`); console.error(`Failed to hide panel: ${JSON.stringify(err)}`);
}); });
``` ```
...@@ -1493,7 +1493,7 @@ hide(callback: AsyncCallback&lt;void&gt;): void ...@@ -1493,7 +1493,7 @@ hide(callback: AsyncCallback&lt;void&gt;): void
**示例:** **示例:**
```ts ```ts
keyboardController.hide((err: Error) => { keyboardController.hide((err: BusinessError) => {
if (err) { if (err) {
console.error(`Failed to hide: ${JSON.stringify(err)}`); console.error(`Failed to hide: ${JSON.stringify(err)}`);
return; return;
...@@ -1529,7 +1529,7 @@ hide(): Promise&lt;void&gt; ...@@ -1529,7 +1529,7 @@ hide(): Promise&lt;void&gt;
```ts ```ts
keyboardController.hide().then(() => { keyboardController.hide().then(() => {
console.log('Succeeded in hiding keyboard.'); console.log('Succeeded in hiding keyboard.');
}).catch((err: Error) => { }).catch((err: BusinessError) => {
console.log(`Failed to hide: ${JSON.stringify(err)}`); console.log(`Failed to hide: ${JSON.stringify(err)}`);
}); });
``` ```
...@@ -1555,7 +1555,7 @@ hideKeyboard(callback: AsyncCallback&lt;void&gt;): void ...@@ -1555,7 +1555,7 @@ hideKeyboard(callback: AsyncCallback&lt;void&gt;): void
**示例:** **示例:**
```ts ```ts
keyboardController.hideKeyboard((err: Error) => { keyboardController.hideKeyboard((err: BusinessError) => {
if (err) { if (err) {
console.error(`Failed to hideKeyboard: ${JSON.stringify(err)}`); console.error(`Failed to hideKeyboard: ${JSON.stringify(err)}`);
return; return;
...@@ -1587,7 +1587,7 @@ hideKeyboard(): Promise&lt;void&gt; ...@@ -1587,7 +1587,7 @@ hideKeyboard(): Promise&lt;void&gt;
```ts ```ts
keyboardController.hideKeyboard().then(() => { keyboardController.hideKeyboard().then(() => {
console.log('Succeeded in hiding keyboard.'); console.log('Succeeded in hiding keyboard.');
}).catch((err: Error) => { }).catch((err: BusinessError) => {
console.log(`Failed to hideKeyboard: ${JSON.stringify(err)}`); console.log(`Failed to hideKeyboard: ${JSON.stringify(err)}`);
}); });
``` ```
...@@ -1671,7 +1671,7 @@ sendKeyFunction(action:number, callback: AsyncCallback&lt;boolean&gt;): void ...@@ -1671,7 +1671,7 @@ sendKeyFunction(action:number, callback: AsyncCallback&lt;boolean&gt;): void
```ts ```ts
let action = 1; let action = 1;
try { try {
inputClient.sendKeyFunction(action, (err: Error, result: boolean) => { inputClient.sendKeyFunction(action, (err: BusinessError, result: boolean) => {
if (err) { if (err) {
console.error(`Failed to sendKeyFunction: ${JSON.stringify(err)}`); console.error(`Failed to sendKeyFunction: ${JSON.stringify(err)}`);
return; return;
...@@ -1726,7 +1726,7 @@ try { ...@@ -1726,7 +1726,7 @@ try {
} else { } else {
console.error('Failed to sendKeyFunction.'); console.error('Failed to sendKeyFunction.');
} }
}).catch((err: Error) => { }).catch((err: BusinessError) => {
console.error(`Failed to sendKeyFunction: ${JSON.stringify(err)}`); console.error(`Failed to sendKeyFunction: ${JSON.stringify(err)}`);
}); });
} catch (err) { } catch (err) {
...@@ -1763,7 +1763,7 @@ getForward(length:number, callback: AsyncCallback&lt;string&gt;): void ...@@ -1763,7 +1763,7 @@ getForward(length:number, callback: AsyncCallback&lt;string&gt;): void
```ts ```ts
let length = 1; let length = 1;
try { try {
inputClient.getForward(length, (err: Error, text: string) => { inputClient.getForward(length, (err: BusinessError, text: string) => {
if (err) { if (err) {
console.error(`Failed to getForward: ${JSON.stringify(err)}`); console.error(`Failed to getForward: ${JSON.stringify(err)}`);
return; return;
...@@ -1811,7 +1811,7 @@ let length = 1; ...@@ -1811,7 +1811,7 @@ let length = 1;
try { try {
inputClient.getForward(length).then((text: string) => { inputClient.getForward(length).then((text: string) => {
console.log('Succeeded in getting forward, text: ' + text); console.log('Succeeded in getting forward, text: ' + text);
}).catch((err: Error) => { }).catch((err: BusinessError) => {
console.error(`Failed to getForward: ${JSON.stringify(err)}`); console.error(`Failed to getForward: ${JSON.stringify(err)}`);
}); });
} catch (err) { } catch (err) {
...@@ -1889,7 +1889,7 @@ getBackward(length:number, callback: AsyncCallback&lt;string&gt;): void ...@@ -1889,7 +1889,7 @@ getBackward(length:number, callback: AsyncCallback&lt;string&gt;): void
```ts ```ts
let length = 1; let length = 1;
try { try {
inputClient.getBackward(length, (err: Error, text: string) => { inputClient.getBackward(length, (err: BusinessError, text: string) => {
if (err) { if (err) {
console.error(`Failed to getBackward: ${JSON.stringify(err)}`); console.error(`Failed to getBackward: ${JSON.stringify(err)}`);
return; return;
...@@ -1937,7 +1937,7 @@ let length = 1; ...@@ -1937,7 +1937,7 @@ let length = 1;
try { try {
inputClient.getBackward(length).then((text: string) => { inputClient.getBackward(length).then((text: string) => {
console.log('Succeeded in getting backward, text: ' + text); console.log('Succeeded in getting backward, text: ' + text);
}).catch((err: Error) => { }).catch((err: BusinessError) => {
console.error(`Failed to getBackward: ${JSON.stringify(err)}`); console.error(`Failed to getBackward: ${JSON.stringify(err)}`);
}); });
} catch (err) { } catch (err) {
...@@ -2015,7 +2015,7 @@ deleteForward(length:number, callback: AsyncCallback&lt;boolean&gt;): void ...@@ -2015,7 +2015,7 @@ deleteForward(length:number, callback: AsyncCallback&lt;boolean&gt;): void
```ts ```ts
let length = 1; let length = 1;
try { try {
inputClient.deleteForward(length, (err: Error, result: boolean) => { inputClient.deleteForward(length, (err: BusinessError, result: boolean) => {
if (err) { if (err) {
console.error(`Failed to deleteForward: ${JSON.stringify(err)}`); console.error(`Failed to deleteForward: ${JSON.stringify(err)}`);
return; return;
...@@ -2071,7 +2071,7 @@ try { ...@@ -2071,7 +2071,7 @@ try {
} else { } else {
console.error('Failed to delete Forward.'); console.error('Failed to delete Forward.');
} }
}).catch((err: Error) => { }).catch((err: BusinessError) => {
console.error(`Failed to deleteForward: ${JSON.stringify(err)}`); console.error(`Failed to deleteForward: ${JSON.stringify(err)}`);
}); });
} catch (err) { } catch (err) {
...@@ -2143,7 +2143,7 @@ deleteBackward(length:number, callback: AsyncCallback&lt;boolean&gt;): void ...@@ -2143,7 +2143,7 @@ deleteBackward(length:number, callback: AsyncCallback&lt;boolean&gt;): void
```ts ```ts
let length = 1; let length = 1;
try { try {
inputClient.deleteBackward(length, (err: Error, result: boolean) => { inputClient.deleteBackward(length, (err: BusinessError, result: boolean) => {
if (err) { if (err) {
console.error(`Failed to deleteBackward: ${JSON.stringify(err)}`); console.error(`Failed to deleteBackward: ${JSON.stringify(err)}`);
return; return;
...@@ -2198,7 +2198,7 @@ inputClient.deleteBackward(length).then((result: boolean) => { ...@@ -2198,7 +2198,7 @@ inputClient.deleteBackward(length).then((result: boolean) => {
} else { } else {
console.error('Failed to deleteBackward.'); console.error('Failed to deleteBackward.');
} }
}).catch((err: Error) => { }).catch((err: BusinessError) => {
console.error(`Failed to deleteBackward: ${JSON.stringify(err)}`); console.error(`Failed to deleteBackward: ${JSON.stringify(err)}`);
}); });
``` ```
...@@ -2265,7 +2265,7 @@ insertText(text:string, callback: AsyncCallback&lt;boolean&gt;): void ...@@ -2265,7 +2265,7 @@ insertText(text:string, callback: AsyncCallback&lt;boolean&gt;): void
**示例:** **示例:**
```ts ```ts
inputClient.insertText('test', (err: Error, result: boolean) => { inputClient.insertText('test', (err: BusinessError, result: boolean) => {
if (err) { if (err) {
console.error(`Failed to insertText: ${JSON.stringify(err)}`); console.error(`Failed to insertText: ${JSON.stringify(err)}`);
return; return;
...@@ -2317,7 +2317,7 @@ try { ...@@ -2317,7 +2317,7 @@ try {
} else { } else {
console.error('Failed to insertText.'); console.error('Failed to insertText.');
} }
}).catch((err: Error) => { }).catch((err: BusinessError) => {
console.error(`Failed to insertText: ${JSON.stringify(err)}`); console.error(`Failed to insertText: ${JSON.stringify(err)}`);
}); });
} catch (err) { } catch (err) {
...@@ -2384,7 +2384,7 @@ getEditorAttribute(callback: AsyncCallback&lt;EditorAttribute&gt;): void ...@@ -2384,7 +2384,7 @@ getEditorAttribute(callback: AsyncCallback&lt;EditorAttribute&gt;): void
**示例:** **示例:**
```ts ```ts
inputClient.getEditorAttribute((err: Error, editorAttribute: inputMethodEngine.EditorAttribute) => { inputClient.getEditorAttribute((err: BusinessError, editorAttribute: inputMethodEngine.EditorAttribute) => {
if (err) { if (err) {
console.error(`Failed to getEditorAttribute: ${JSON.stringify(err)}`); console.error(`Failed to getEditorAttribute: ${JSON.stringify(err)}`);
return; return;
...@@ -2422,7 +2422,7 @@ getEditorAttribute(): Promise&lt;EditorAttribute&gt; ...@@ -2422,7 +2422,7 @@ getEditorAttribute(): Promise&lt;EditorAttribute&gt;
inputClient.getEditorAttribute().then((editorAttribute: inputMethodEngine.EditorAttribute) => { inputClient.getEditorAttribute().then((editorAttribute: inputMethodEngine.EditorAttribute) => {
console.log('editorAttribute.inputPattern: ' + JSON.stringify(editorAttribute.inputPattern)); console.log('editorAttribute.inputPattern: ' + JSON.stringify(editorAttribute.inputPattern));
console.log('editorAttribute.enterKeyType: ' + JSON.stringify(editorAttribute.enterKeyType)); console.log('editorAttribute.enterKeyType: ' + JSON.stringify(editorAttribute.enterKeyType));
}).catch((err: Error) => { }).catch((err: BusinessError) => {
console.error(`Failed to getEditorAttribute: ${JSON.stringify(err)}`); console.error(`Failed to getEditorAttribute: ${JSON.stringify(err)}`);
}); });
``` ```
...@@ -2487,7 +2487,7 @@ moveCursor(direction: number, callback: AsyncCallback&lt;void&gt;): void ...@@ -2487,7 +2487,7 @@ moveCursor(direction: number, callback: AsyncCallback&lt;void&gt;): void
```ts ```ts
try { try {
inputClient.moveCursor(inputMethodEngine.Direction.CURSOR_UP, (err: Error) => { inputClient.moveCursor(inputMethodEngine.Direction.CURSOR_UP, (err: BusinessError) => {
if (err) { if (err) {
console.error(`Failed to moveCursor: ${JSON.stringify(err)}`); console.error(`Failed to moveCursor: ${JSON.stringify(err)}`);
return; return;
...@@ -2533,7 +2533,7 @@ moveCursor(direction: number): Promise&lt;void&gt; ...@@ -2533,7 +2533,7 @@ moveCursor(direction: number): Promise&lt;void&gt;
try { try {
inputClient.moveCursor(inputMethodEngine.Direction.CURSOR_UP).then(() => { inputClient.moveCursor(inputMethodEngine.Direction.CURSOR_UP).then(() => {
console.log('Succeeded in moving cursor.'); console.log('Succeeded in moving cursor.');
}).catch((err: Error) => { }).catch((err: BusinessError) => {
console.error(`Failed to moveCursor: ${JSON.stringify(err)}`); console.error(`Failed to moveCursor: ${JSON.stringify(err)}`);
}); });
} catch (err) { } catch (err) {
...@@ -2603,7 +2603,7 @@ selectByRange(range: Range, callback: AsyncCallback&lt;void&gt;): void ...@@ -2603,7 +2603,7 @@ selectByRange(range: Range, callback: AsyncCallback&lt;void&gt;): void
```ts ```ts
try { try {
let range: inputMethodEngine.Range = { start: 0, end: 1 }; let range: inputMethodEngine.Range = { start: 0, end: 1 };
inputClient.selectByRange(range, (err: Error) => { inputClient.selectByRange(range, (err: BusinessError) => {
if (err) { if (err) {
console.error(`Failed to selectByRange: ${JSON.stringify(err)}`); console.error(`Failed to selectByRange: ${JSON.stringify(err)}`);
return; return;
...@@ -2651,7 +2651,7 @@ try { ...@@ -2651,7 +2651,7 @@ try {
let range: inputMethodEngine.Range = { start: 0, end: 1 }; let range: inputMethodEngine.Range = { start: 0, end: 1 };
inputClient.selectByRange(range).then(() => { inputClient.selectByRange(range).then(() => {
console.log('Succeeded in selecting by range.'); console.log('Succeeded in selecting by range.');
}).catch((err: Error) => { }).catch((err: BusinessError) => {
console.error(`Failed to selectByRange: ${JSON.stringify(err)}`); console.error(`Failed to selectByRange: ${JSON.stringify(err)}`);
}); });
} catch (err) { } catch (err) {
...@@ -2723,7 +2723,7 @@ selectByMovement(movement: Movement, callback: AsyncCallback&lt;void&gt;): void ...@@ -2723,7 +2723,7 @@ selectByMovement(movement: Movement, callback: AsyncCallback&lt;void&gt;): void
```ts ```ts
try { try {
let movement: inputMethodEngine.Movement = { direction: 1 }; let movement: inputMethodEngine.Movement = { direction: 1 };
inputClient.selectByMovement(movement, (err: Error) => { inputClient.selectByMovement(movement, (err: BusinessError) => {
if (err) { if (err) {
console.error(`Failed to selectByMovement: ${JSON.stringify(err)}`); console.error(`Failed to selectByMovement: ${JSON.stringify(err)}`);
return; return;
...@@ -2771,7 +2771,7 @@ try { ...@@ -2771,7 +2771,7 @@ try {
let movement: inputMethodEngine.Movement = { direction: 1 }; let movement: inputMethodEngine.Movement = { direction: 1 };
inputClient.selectByMovement(movement).then(() => { inputClient.selectByMovement(movement).then(() => {
console.log('Succeeded in selecting by movement.'); console.log('Succeeded in selecting by movement.');
}).catch((err: Error) => { }).catch((err: BusinessError) => {
console.error(`Failed to selectByMovement: ${JSON.stringify(err)}`); console.error(`Failed to selectByMovement: ${JSON.stringify(err)}`);
}); });
} catch (err) { } catch (err) {
...@@ -2840,7 +2840,7 @@ getTextIndexAtCursor(callback: AsyncCallback&lt;number&gt;): void ...@@ -2840,7 +2840,7 @@ getTextIndexAtCursor(callback: AsyncCallback&lt;number&gt;): void
**示例:** **示例:**
```ts ```ts
inputClient.getTextIndexAtCursor((err: Error, index: number) => { inputClient.getTextIndexAtCursor((err: BusinessError, index: number) => {
if (err) { if (err) {
console.error(`Failed to getTextIndexAtCursor: ${JSON.stringify(err)}`); console.error(`Failed to getTextIndexAtCursor: ${JSON.stringify(err)}`);
return; return;
...@@ -2877,7 +2877,7 @@ getTextIndexAtCursor(): Promise&lt;number&gt; ...@@ -2877,7 +2877,7 @@ getTextIndexAtCursor(): Promise&lt;number&gt;
```ts ```ts
inputClient.getTextIndexAtCursor().then((index: number) => { inputClient.getTextIndexAtCursor().then((index: number) => {
console.log('Succeeded in getTextIndexAtCursor: ' + index); console.log('Succeeded in getTextIndexAtCursor: ' + index);
}).catch((err: Error) => { }).catch((err: BusinessError) => {
console.error(`Failed to getTextIndexAtCursor: ${JSON.stringify(err)}`); console.error(`Failed to getTextIndexAtCursor: ${JSON.stringify(err)}`);
}); });
``` ```
...@@ -2948,7 +2948,7 @@ sendExtendAction(action: ExtendAction, callback: AsyncCallback&lt;void&gt;): voi ...@@ -2948,7 +2948,7 @@ sendExtendAction(action: ExtendAction, callback: AsyncCallback&lt;void&gt;): voi
```ts ```ts
try { try {
inputClient.sendExtendAction(inputMethodEngine.ExtendAction.COPY, (err: Error) => { inputClient.sendExtendAction(inputMethodEngine.ExtendAction.COPY, (err: BusinessError) => {
if (err) { if (err) {
console.error(`Failed to sendExtendAction: ${JSON.stringify(err)}`); console.error(`Failed to sendExtendAction: ${JSON.stringify(err)}`);
return; return;
...@@ -2999,7 +2999,7 @@ sendExtendAction(action: ExtendAction): Promise&lt;void&gt; ...@@ -2999,7 +2999,7 @@ sendExtendAction(action: ExtendAction): Promise&lt;void&gt;
try { try {
inputClient.sendExtendAction(inputMethodEngine.ExtendAction.COPY).then(() => { inputClient.sendExtendAction(inputMethodEngine.ExtendAction.COPY).then(() => {
console.log('Succeeded in sending extend action.'); console.log('Succeeded in sending extend action.');
}).catch((err: Error) => { }).catch((err: BusinessError) => {
console.error(`Failed to sendExtendAction: ${JSON.stringify(err)}`); console.error(`Failed to sendExtendAction: ${JSON.stringify(err)}`);
}); });
} catch(err) { } catch(err) {
...@@ -3093,7 +3093,7 @@ getForward(length:number, callback: AsyncCallback&lt;string&gt;): void ...@@ -3093,7 +3093,7 @@ getForward(length:number, callback: AsyncCallback&lt;string&gt;): void
```ts ```ts
let length = 1; let length = 1;
textInputClient.getForward(length, (err: Error, text: string) => { textInputClient.getForward(length, (err: BusinessError, text: string) => {
if (err) { if (err) {
console.error(`Failed to getForward: ${JSON.stringify(err)}`); console.error(`Failed to getForward: ${JSON.stringify(err)}`);
return; return;
...@@ -3132,7 +3132,7 @@ getForward(length:number): Promise&lt;string&gt; ...@@ -3132,7 +3132,7 @@ getForward(length:number): Promise&lt;string&gt;
let length = 1; let length = 1;
textInputClient.getForward(length).then((text: string) => { textInputClient.getForward(length).then((text: string) => {
console.log('Succeeded in getting forward, text: ' + text); console.log('Succeeded in getting forward, text: ' + text);
}).catch((err: Error) => { }).catch((err: BusinessError) => {
console.error(`Failed to getForward: ${JSON.stringify(err)}`); console.error(`Failed to getForward: ${JSON.stringify(err)}`);
}); });
``` ```
...@@ -3160,7 +3160,7 @@ getBackward(length:number, callback: AsyncCallback&lt;string&gt;): void ...@@ -3160,7 +3160,7 @@ getBackward(length:number, callback: AsyncCallback&lt;string&gt;): void
```ts ```ts
let length = 1; let length = 1;
textInputClient.getBackward(length, (err: Error, text: string) => { textInputClient.getBackward(length, (err: BusinessError, text: string) => {
if (err) { if (err) {
console.error(`Failed to getBackward: ${JSON.stringify(err)}`); console.error(`Failed to getBackward: ${JSON.stringify(err)}`);
return; return;
...@@ -3199,7 +3199,7 @@ getBackward(length:number): Promise&lt;string&gt; ...@@ -3199,7 +3199,7 @@ getBackward(length:number): Promise&lt;string&gt;
let length = 1; let length = 1;
textInputClient.getBackward(length).then((text: string) => { textInputClient.getBackward(length).then((text: string) => {
console.log('Succeeded in getting backward: ' + JSON.stringify(text)); console.log('Succeeded in getting backward: ' + JSON.stringify(text));
}).catch((err: Error) => { }).catch((err: BusinessError) => {
console.error(`Failed to getBackward: ${JSON.stringify(err)}`); console.error(`Failed to getBackward: ${JSON.stringify(err)}`);
}); });
``` ```
...@@ -3227,7 +3227,7 @@ deleteForward(length:number, callback: AsyncCallback&lt;boolean&gt;): void ...@@ -3227,7 +3227,7 @@ deleteForward(length:number, callback: AsyncCallback&lt;boolean&gt;): void
```ts ```ts
let length = 1; let length = 1;
textInputClient.deleteForward(length, (err: Error, result: boolean) => { textInputClient.deleteForward(length, (err: BusinessError, result: boolean) => {
if (err) { if (err) {
console.error(`Failed to deleteForward: ${JSON.stringify(err)}`); console.error(`Failed to deleteForward: ${JSON.stringify(err)}`);
return; return;
...@@ -3274,7 +3274,7 @@ textInputClient.deleteForward(length).then((result: boolean) => { ...@@ -3274,7 +3274,7 @@ textInputClient.deleteForward(length).then((result: boolean) => {
} else { } else {
console.error('Failed to delete forward.'); console.error('Failed to delete forward.');
} }
}).catch((err: Error) => { }).catch((err: BusinessError) => {
console.error(`Failed to deleteForward: ${JSON.stringify(err)}`); console.error(`Failed to deleteForward: ${JSON.stringify(err)}`);
}); });
``` ```
...@@ -3302,7 +3302,7 @@ deleteBackward(length:number, callback: AsyncCallback&lt;boolean&gt;): void ...@@ -3302,7 +3302,7 @@ deleteBackward(length:number, callback: AsyncCallback&lt;boolean&gt;): void
```ts ```ts
let length = 1; let length = 1;
textInputClient.deleteBackward(length, (err: Error, result: boolean) => { textInputClient.deleteBackward(length, (err: BusinessError, result: boolean) => {
if (err) { if (err) {
console.error(`Failed to deleteBackward: ${JSON.stringify(err)}`); console.error(`Failed to deleteBackward: ${JSON.stringify(err)}`);
return; return;
...@@ -3349,7 +3349,7 @@ textInputClient.deleteBackward(length).then((result: boolean) => { ...@@ -3349,7 +3349,7 @@ textInputClient.deleteBackward(length).then((result: boolean) => {
} else { } else {
console.error('Failed to deleteBackward.'); console.error('Failed to deleteBackward.');
} }
}).catch((err: Error) => { }).catch((err: BusinessError) => {
console.error(`Failed to deleteBackward: ${JSON.stringify(err)}`); console.error(`Failed to deleteBackward: ${JSON.stringify(err)}`);
}); });
``` ```
...@@ -3376,7 +3376,7 @@ sendKeyFunction(action: number, callback: AsyncCallback&lt;boolean&gt;): void ...@@ -3376,7 +3376,7 @@ sendKeyFunction(action: number, callback: AsyncCallback&lt;boolean&gt;): void
```ts ```ts
let action = 1; let action = 1;
textInputClient.sendKeyFunction(action, (err: Error, result: boolean) => { textInputClient.sendKeyFunction(action, (err: BusinessError, result: boolean) => {
if (err) { if (err) {
console.error(`Failed to sendKeyFunction: ${JSON.stringify(err)}`); console.error(`Failed to sendKeyFunction: ${JSON.stringify(err)}`);
return; return;
...@@ -3423,7 +3423,7 @@ textInputClient.sendKeyFunction(action).then((result: boolean) => { ...@@ -3423,7 +3423,7 @@ textInputClient.sendKeyFunction(action).then((result: boolean) => {
} else { } else {
console.error('Failed to sendKeyFunction.'); console.error('Failed to sendKeyFunction.');
} }
}).catch((err: Error) => { }).catch((err: BusinessError) => {
console.error(`Failed to sendKeyFunction: ${JSON.stringify(err)}`); console.error(`Failed to sendKeyFunction: ${JSON.stringify(err)}`);
}); });
``` ```
...@@ -3450,7 +3450,7 @@ insertText(text:string, callback: AsyncCallback&lt;boolean&gt;): void ...@@ -3450,7 +3450,7 @@ insertText(text:string, callback: AsyncCallback&lt;boolean&gt;): void
**示例:** **示例:**
```ts ```ts
textInputClient.insertText('test', (err: Error, result: boolean) => { textInputClient.insertText('test', (err: BusinessError, result: boolean) => {
if (err) { if (err) {
console.error(`Failed to insertText: ${JSON.stringify(err)}`); console.error(`Failed to insertText: ${JSON.stringify(err)}`);
return; return;
...@@ -3496,7 +3496,7 @@ textInputClient.insertText('test').then((result: boolean) => { ...@@ -3496,7 +3496,7 @@ textInputClient.insertText('test').then((result: boolean) => {
} else { } else {
console.error('Failed to insertText.'); console.error('Failed to insertText.');
} }
}).catch((err: Error) => { }).catch((err: BusinessError) => {
console.error(`Failed to insertText: ${JSON.stringify(err)}`); console.error(`Failed to insertText: ${JSON.stringify(err)}`);
}); });
``` ```
...@@ -3522,7 +3522,7 @@ getEditorAttribute(callback: AsyncCallback&lt;EditorAttribute&gt;): void ...@@ -3522,7 +3522,7 @@ getEditorAttribute(callback: AsyncCallback&lt;EditorAttribute&gt;): void
**示例:** **示例:**
```ts ```ts
textInputClient.getEditorAttribute((err: Error, editorAttribute: inputMethodEngine.EditorAttribute) => { textInputClient.getEditorAttribute((err: BusinessError, editorAttribute: inputMethodEngine.EditorAttribute) => {
if (err) { if (err) {
console.error(`Failed to getEditorAttribute: ${JSON.stringify(err)}`); console.error(`Failed to getEditorAttribute: ${JSON.stringify(err)}`);
return; return;
...@@ -3556,7 +3556,7 @@ getEditorAttribute(): Promise&lt;EditorAttribute&gt; ...@@ -3556,7 +3556,7 @@ getEditorAttribute(): Promise&lt;EditorAttribute&gt;
textInputClient.getEditorAttribute().then((editorAttribute: inputMethodEngine.EditorAttribute) => { textInputClient.getEditorAttribute().then((editorAttribute: inputMethodEngine.EditorAttribute) => {
console.log('editorAttribute.inputPattern: ' + JSON.stringify(editorAttribute.inputPattern)); console.log('editorAttribute.inputPattern: ' + JSON.stringify(editorAttribute.inputPattern));
console.log('editorAttribute.enterKeyType: ' + JSON.stringify(editorAttribute.enterKeyType)); console.log('editorAttribute.enterKeyType: ' + JSON.stringify(editorAttribute.enterKeyType));
}).catch((err: Error) => { }).catch((err: BusinessError) => {
console.error(`Failed to getEditorAttribute: ${JSON.stringify(err)}`); console.error(`Failed to getEditorAttribute: ${JSON.stringify(err)}`);
}); });
``` ```
......
...@@ -103,10 +103,9 @@ uploadFile(context: BaseContext, config: UploadConfig): Promise&lt;UploadTask&gt ...@@ -103,10 +103,9 @@ uploadFile(context: BaseContext, config: UploadConfig): Promise&lt;UploadTask&gt
**示例:** **示例:**
```js ```ts
let uploadTask; let uploadTask: request.UploadTask;
let context; let uploadConfig: request.UploadConfig = {
let uploadConfig = {
url: 'http://patch', url: 'http://patch',
header: { key1: "value1", key2: "value2" }, header: { key1: "value1", key2: "value2" },
method: "POST", method: "POST",
...@@ -114,13 +113,13 @@ uploadFile(context: BaseContext, config: UploadConfig): Promise&lt;UploadTask&gt ...@@ -114,13 +113,13 @@ uploadFile(context: BaseContext, config: UploadConfig): Promise&lt;UploadTask&gt
data: [{ name: "name123", value: "123" }], data: [{ name: "name123", value: "123" }],
}; };
try { try {
request.uploadFile(context, uploadConfig).then((data) => { request.uploadFile(this.context, uploadConfig).then((data: request.UploadTask) => {
uploadTask = data; uploadTask = data;
}).catch((err) => { }).catch((err: BusinessError) => {
console.error(`Failed to request the upload. Code: ${err.code}, message: ${err.message}`); console.error(`Failed to request the upload. Code: ${err.code}, message: ${err.message}`);
}); });
} catch (err) { } catch (err) {
console.error(`Failed to request the upload. Code: ${err.code}, message: ${err.message}`); console.error(`Failed to request the upload. err: ${JSON.stringify(err)}`);
} }
``` ```
...@@ -157,10 +156,9 @@ uploadFile(context: BaseContext, config: UploadConfig, callback: AsyncCallback&l ...@@ -157,10 +156,9 @@ uploadFile(context: BaseContext, config: UploadConfig, callback: AsyncCallback&l
**示例:** **示例:**
```js ```ts
let uploadTask; let uploadTask: request.UploadTask;
let context; let uploadConfig: request.UploadConfig = {
let uploadConfig = {
url: 'http://patch', url: 'http://patch',
header: { key1: "value1", key2: "value2" }, header: { key1: "value1", key2: "value2" },
method: "POST", method: "POST",
...@@ -168,7 +166,7 @@ uploadFile(context: BaseContext, config: UploadConfig, callback: AsyncCallback&l ...@@ -168,7 +166,7 @@ uploadFile(context: BaseContext, config: UploadConfig, callback: AsyncCallback&l
data: [{ name: "name123", value: "123" }], data: [{ name: "name123", value: "123" }],
}; };
try { try {
request.uploadFile(context, uploadConfig, (err, data) => { request.uploadFile(this.context, uploadConfig, (err: BusinessError, data: request.UploadTask) => {
if (err) { if (err) {
console.error(`Failed to request the upload. Code: ${err.code}, message: ${err.message}`); console.error(`Failed to request the upload. Code: ${err.code}, message: ${err.message}`);
return; return;
...@@ -176,7 +174,7 @@ uploadFile(context: BaseContext, config: UploadConfig, callback: AsyncCallback&l ...@@ -176,7 +174,7 @@ uploadFile(context: BaseContext, config: UploadConfig, callback: AsyncCallback&l
uploadTask = data; uploadTask = data;
}); });
} catch (err) { } catch (err) {
console.error(`Failed to request the upload. Code: ${err.code}, message: ${err.message}`); console.error(`Failed to request the upload. err: ${JSON.stringify(err)}`);
} }
``` ```
...@@ -306,8 +304,8 @@ on(type: 'progress', callback:(uploadedSize: number, totalSize: number) =&gt; vo ...@@ -306,8 +304,8 @@ on(type: 'progress', callback:(uploadedSize: number, totalSize: number) =&gt; vo
**示例:** **示例:**
```js ```ts
let upProgressCallback = (uploadedSize, totalSize) => { let upProgressCallback = (uploadedSize: number, totalSize: number) => {
console.info("upload totalSize:" + totalSize + " uploadedSize:" + uploadedSize); console.info("upload totalSize:" + totalSize + " uploadedSize:" + uploadedSize);
}; };
uploadTask.on('progress', upProgressCallback); uploadTask.on('progress', upProgressCallback);
...@@ -339,8 +337,8 @@ on(type: 'headerReceive', callback: (header: object) =&gt; void): void ...@@ -339,8 +337,8 @@ on(type: 'headerReceive', callback: (header: object) =&gt; void): void
**示例:** **示例:**
```js ```ts
let headerCallback = (headers) => { let headerCallback = (headers: object) => {
console.info("upOnHeader headers:" + JSON.stringify(headers)); console.info("upOnHeader headers:" + JSON.stringify(headers));
}; };
uploadTask.on('headerReceive', headerCallback); uploadTask.on('headerReceive', headerCallback);
...@@ -372,16 +370,16 @@ on(type: 'headerReceive', callback: (header: object) =&gt; void): void ...@@ -372,16 +370,16 @@ on(type: 'headerReceive', callback: (header: object) =&gt; void): void
**示例:** **示例:**
```js ```ts
let upCompleteCallback = (taskStates) => { let upCompleteCallback = (taskStates: Array<request.TaskState>) => {
for (let i = 0; i < taskStates.length; i++ ) { for (let i = 0; i < taskStates.length; i++) {
console.info("upOnComplete taskState:" + JSON.stringify(taskStates[i])); console.info("upOnComplete taskState:" + JSON.stringify(taskStates[i]));
} }
}; };
uploadTask.on('complete', upCompleteCallback); uploadTask.on('complete', upCompleteCallback);
let upFailCallback = (taskStates) => { let upFailCallback = (taskStates: Array<request.TaskState>) => {
for (let i = 0; i < taskStates.length; i++ ) { for (let i = 0; i < taskStates.length; i++) {
console.info("upOnFail taskState:" + JSON.stringify(taskStates[i])); console.info("upOnFail taskState:" + JSON.stringify(taskStates[i]));
} }
}; };
...@@ -408,8 +406,8 @@ off(type: 'progress', callback?: (uploadedSize: number, totalSize: number) =&g ...@@ -408,8 +406,8 @@ off(type: 'progress', callback?: (uploadedSize: number, totalSize: number) =&g
**示例:** **示例:**
```js ```ts
let upProgressCallback = (uploadedSize, totalSize) => { let upProgressCallback = (uploadedSize: number, totalSize: number) => {
console.info('Upload delete progress notification.' + 'totalSize:' + totalSize + 'uploadedSize:' + uploadedSize); console.info('Upload delete progress notification.' + 'totalSize:' + totalSize + 'uploadedSize:' + uploadedSize);
}; };
uploadTask.off('progress', upProgressCallback); uploadTask.off('progress', upProgressCallback);
...@@ -435,8 +433,8 @@ off(type: 'headerReceive', callback?: (header: object) =&gt; void): void ...@@ -435,8 +433,8 @@ off(type: 'headerReceive', callback?: (header: object) =&gt; void): void
**示例:** **示例:**
```js ```ts
let headerCallback = (header) => { let headerCallback = (header: object) => {
console.info(`Upload delete headerReceive notification. header: ${JSON.stringify(header)}`); console.info(`Upload delete headerReceive notification. header: ${JSON.stringify(header)}`);
}; };
uploadTask.off('headerReceive', headerCallback); uploadTask.off('headerReceive', headerCallback);
...@@ -461,18 +459,18 @@ off(type: 'headerReceive', callback?: (header: object) =&gt; void): void ...@@ -461,18 +459,18 @@ off(type: 'headerReceive', callback?: (header: object) =&gt; void): void
**示例:** **示例:**
```js ```ts
let upCompleteCallback = (taskStates) => { let upCompleteCallback = (taskStates: Array<request.TaskState>) => {
console.info('Upload delete complete notification.'); console.info('Upload delete complete notification.');
for (let i = 0; i < taskStates.length; i++ ) { for (let i = 0; i < taskStates.length; i++) {
console.info('taskState:' + JSON.stringify(taskStates[i])); console.info('taskState:' + JSON.stringify(taskStates[i]));
} }
}; };
uploadTask.off('complete', upCompleteCallback); uploadTask.off('complete', upCompleteCallback);
let upFailCallback = (taskStates) => { let upFailCallback = (taskStates: Array<request.TaskState>) => {
console.info('Upload delete fail notification.'); console.info('Upload delete fail notification.');
for (let i = 0; i < taskStates.length; i++ ) { for (let i = 0; i < taskStates.length; i++) {
console.info('taskState:' + JSON.stringify(taskStates[i])); console.info('taskState:' + JSON.stringify(taskStates[i]));
} }
}; };
...@@ -496,10 +494,10 @@ delete(): Promise&lt;boolean&gt; ...@@ -496,10 +494,10 @@ delete(): Promise&lt;boolean&gt;
**示例:** **示例:**
```js ```ts
uploadTask.delete().then((result) => { uploadTask.delete().then((result: boolean) => {
console.info('Succeeded in deleting the upload task.'); console.info('Succeeded in deleting the upload task.');
}).catch((err) => { }).catch((err: BusinessError) => {
console.error(`Failed to delete the upload task. Code: ${err.code}, message: ${err.message}`); console.error(`Failed to delete the upload task. Code: ${err.code}, message: ${err.message}`);
}); });
``` ```
...@@ -523,8 +521,8 @@ delete(callback: AsyncCallback&lt;boolean&gt;): void ...@@ -523,8 +521,8 @@ delete(callback: AsyncCallback&lt;boolean&gt;): void
**示例:** **示例:**
```js ```ts
uploadTask.delete((err, result) => { uploadTask.delete((err: BusinessError, result: boolean) => {
if (err) { if (err) {
console.error(`Failed to delete the upload task. Code: ${err.code}, message: ${err.message}`); console.error(`Failed to delete the upload task. Code: ${err.code}, message: ${err.message}`);
return; return;
...@@ -688,17 +686,16 @@ downloadFile(context: BaseContext, config: DownloadConfig): Promise&lt;DownloadT ...@@ -688,17 +686,16 @@ downloadFile(context: BaseContext, config: DownloadConfig): Promise&lt;DownloadT
**示例:** **示例:**
```js ```ts
let downloadTask; let downloadTask: request.DownloadTask;
let context;
try { try {
request.downloadFile(context, { url: 'https://xxxx/xxxx.hap' }).then((data) => { request.downloadFile(this.context, { url: 'https://xxxx/xxxx.hap' }).then((data: request.DownloadTask) => {
downloadTask = data; downloadTask = data;
}).catch((err) => { }).catch((err: BusinessError) => {
console.error(`Failed to request the download. Code: ${err.code}, message: ${err.message}`); console.error(`Failed to request the download. Code: ${err.code}, message: ${err.message}`);
}) })
} catch (err) { } catch (err) {
console.error(`Failed to request the download. Code: ${err.code}, message: ${err.message}`); console.error(`Failed to request the download. err: ${JSON.stringify(err)}`);
} }
``` ```
...@@ -738,12 +735,13 @@ downloadFile(context: BaseContext, config: DownloadConfig, callback: AsyncCallba ...@@ -738,12 +735,13 @@ downloadFile(context: BaseContext, config: DownloadConfig, callback: AsyncCallba
**示例:** **示例:**
```js ```ts
let downloadTask; let downloadTask: request.DownloadTask;
let context;
try { try {
request.downloadFile(context, { url: 'https://xxxx/xxxxx.hap', request.downloadFile(this.context, {
filePath: 'xxx/xxxxx.hap'}, (err, data) => { url: 'https://xxxx/xxxxx.hap',
filePath: 'xxx/xxxxx.hap'
}, (err: BusinessError, data: request.DownloadTask) => {
if (err) { if (err) {
console.error(`Failed to request the download. Code: ${err.code}, message: ${err.message}`); console.error(`Failed to request the download. Code: ${err.code}, message: ${err.message}`);
return; return;
...@@ -751,7 +749,7 @@ downloadFile(context: BaseContext, config: DownloadConfig, callback: AsyncCallba ...@@ -751,7 +749,7 @@ downloadFile(context: BaseContext, config: DownloadConfig, callback: AsyncCallba
downloadTask = data; downloadTask = data;
}); });
} catch (err) { } catch (err) {
console.error(`Failed to request the download. Code: ${err.code}, message: ${err.message}`); console.error(`Failed to request the download. err: ${JSON.stringify(err)}`);
} }
``` ```
...@@ -867,8 +865,8 @@ on(type: 'progress', callback:(receivedSize: number, totalSize: number) =&gt; vo ...@@ -867,8 +865,8 @@ on(type: 'progress', callback:(receivedSize: number, totalSize: number) =&gt; vo
**示例:** **示例:**
```js ```ts
let progresCallback = (receivedSize, totalSize) => { let progresCallback = (receivedSize: number, totalSize: number) => {
console.info("download receivedSize:" + receivedSize + " totalSize:" + totalSize); console.info("download receivedSize:" + receivedSize + " totalSize:" + totalSize);
}; };
downloadTask.on('progress', progresCallback); downloadTask.on('progress', progresCallback);
...@@ -894,8 +892,8 @@ off(type: 'progress', callback?: (receivedSize: number, totalSize: number) =&gt; ...@@ -894,8 +892,8 @@ off(type: 'progress', callback?: (receivedSize: number, totalSize: number) =&gt;
**示例:** **示例:**
```js ```ts
let progresCallback = (receivedSize, totalSize) => { let progresCallback = (receivedSize: number, totalSize: number) => {
console.info('Download delete progress notification.' + 'receivedSize:' + receivedSize + 'totalSize:' + totalSize); console.info('Download delete progress notification.' + 'receivedSize:' + receivedSize + 'totalSize:' + totalSize);
}; };
downloadTask.off('progress', progresCallback); downloadTask.off('progress', progresCallback);
...@@ -921,7 +919,7 @@ on(type: 'complete'|'pause'|'remove', callback:() =&gt; void): void ...@@ -921,7 +919,7 @@ on(type: 'complete'|'pause'|'remove', callback:() =&gt; void): void
**示例:** **示例:**
```js ```ts
let completeCallback = () => { let completeCallback = () => {
console.info('Download task completed.'); console.info('Download task completed.');
}; };
...@@ -958,7 +956,7 @@ off(type: 'complete'|'pause'|'remove', callback?:() =&gt; void): void ...@@ -958,7 +956,7 @@ off(type: 'complete'|'pause'|'remove', callback?:() =&gt; void): void
**示例:** **示例:**
```js ```ts
let completeCallback = () => { let completeCallback = () => {
console.info('Download delete complete notification.'); console.info('Download delete complete notification.');
}; };
...@@ -1001,8 +999,8 @@ on(type: 'fail', callback: (err: number) =&gt; void): void ...@@ -1001,8 +999,8 @@ on(type: 'fail', callback: (err: number) =&gt; void): void
**示例:** **示例:**
```js ```ts
let failCallback = (err) => { let failCallback = (err: BusinessError) => {
console.error(`Failed to download the task. Code: ${err.code}, message: ${err.message}`); console.error(`Failed to download the task. Code: ${err.code}, message: ${err.message}`);
}; };
downloadTask.on('fail', failCallback); downloadTask.on('fail', failCallback);
...@@ -1028,8 +1026,8 @@ off(type: 'fail', callback?: (err: number) =&gt; void): void ...@@ -1028,8 +1026,8 @@ off(type: 'fail', callback?: (err: number) =&gt; void): void
**示例:** **示例:**
```js ```ts
let failCallback = (err) => { let failCallback = (err: BusinessError) => {
console.error(`Failed to download the task. Code: ${err.code}, message: ${err.message}`); console.error(`Failed to download the task. Code: ${err.code}, message: ${err.message}`);
}; };
downloadTask.off('fail', failCallback); downloadTask.off('fail', failCallback);
...@@ -1053,10 +1051,10 @@ delete(): Promise&lt;boolean&gt; ...@@ -1053,10 +1051,10 @@ delete(): Promise&lt;boolean&gt;
**示例:** **示例:**
```js ```ts
downloadTask.delete().then((result) => { downloadTask.delete().then((result: boolean) => {
console.info('Succeeded in removing the download task.'); console.info('Succeeded in removing the download task.');
}).catch ((err) => { }).catch((err: BusinessError) => {
console.error(`Failed to remove the download task. Code: ${err.code}, message: ${err.message}`); console.error(`Failed to remove the download task. Code: ${err.code}, message: ${err.message}`);
}); });
``` ```
...@@ -1080,12 +1078,12 @@ delete(callback: AsyncCallback&lt;boolean&gt;): void ...@@ -1080,12 +1078,12 @@ delete(callback: AsyncCallback&lt;boolean&gt;): void
**示例:** **示例:**
```js ```ts
downloadTask.delete((err, result)=>{ downloadTask.delete((err: BusinessError, result: boolean) => {
if(err) { if (err) {
console.error(`Failed to remove the download task. Code: ${err.code}, message: ${err.message}`); console.error(`Failed to remove the download task. Code: ${err.code}, message: ${err.message}`);
return; return;
} }
console.info('Succeeded in removing the download task.'); console.info('Succeeded in removing the download task.');
}); });
``` ```
...@@ -1109,10 +1107,10 @@ getTaskInfo(): Promise&lt;DownloadInfo&gt; ...@@ -1109,10 +1107,10 @@ getTaskInfo(): Promise&lt;DownloadInfo&gt;
**示例:** **示例:**
```js ```ts
downloadTask.getTaskInfo().then((downloadInfo) => { downloadTask.getTaskInfo().then((downloadInfo: request.DownloadInfo) => {
console.info('Succeeded in querying the download task') console.info('Succeeded in querying the download task')
}) .catch((err) => { }).catch((err: BusinessError) => {
console.error(`Failed to query the download task. Code: ${err.code}, message: ${err.message}`) console.error(`Failed to query the download task. Code: ${err.code}, message: ${err.message}`)
}); });
``` ```
...@@ -1136,9 +1134,9 @@ getTaskInfo(callback: AsyncCallback&lt;DownloadInfo&gt;): void ...@@ -1136,9 +1134,9 @@ getTaskInfo(callback: AsyncCallback&lt;DownloadInfo&gt;): void
**示例:** **示例:**
```js ```ts
downloadTask.getTaskInfo((err, downloadInfo)=>{ downloadTask.getTaskInfo((err: BusinessError, downloadInfo: request.DownloadInfo) => {
if(err) { if (err) {
console.error(`Failed to query the download mimeType. Code: ${err.code}, message: ${err.message}`); console.error(`Failed to query the download mimeType. Code: ${err.code}, message: ${err.message}`);
} else { } else {
console.info('Succeeded in querying the download mimeType'); console.info('Succeeded in querying the download mimeType');
...@@ -1165,10 +1163,10 @@ getTaskMimeType(): Promise&lt;string&gt; ...@@ -1165,10 +1163,10 @@ getTaskMimeType(): Promise&lt;string&gt;
**示例:** **示例:**
```js ```ts
downloadTask.getTaskMimeType().then((data) => { downloadTask.getTaskMimeType().then((data: string) => {
console.info('Succeeded in querying the download MimeType'); console.info('Succeeded in querying the download MimeType');
}).catch((err) => { }).catch((err: BusinessError) => {
console.error(`Failed to query the download MimeType. Code: ${err.code}, message: ${err.message}`) console.error(`Failed to query the download MimeType. Code: ${err.code}, message: ${err.message}`)
}); });
``` ```
...@@ -1192,9 +1190,9 @@ getTaskMimeType(callback: AsyncCallback&lt;string&gt;): void; ...@@ -1192,9 +1190,9 @@ getTaskMimeType(callback: AsyncCallback&lt;string&gt;): void;
**示例:** **示例:**
```js ```ts
downloadTask.getTaskMimeType((err, data)=>{ downloadTask.getTaskMimeType((err: BusinessError, data: string) => {
if(err) { if (err) {
console.error(`Failed to query the download mimeType. Code: ${err.code}, message: ${err.message}`); console.error(`Failed to query the download mimeType. Code: ${err.code}, message: ${err.message}`);
} else { } else {
console.info('Succeeded in querying the download mimeType'); console.info('Succeeded in querying the download mimeType');
...@@ -1221,10 +1219,10 @@ suspend(): Promise&lt;boolean&gt; ...@@ -1221,10 +1219,10 @@ suspend(): Promise&lt;boolean&gt;
**示例:** **示例:**
```js ```ts
downloadTask.suspend().then((result) => { downloadTask.suspend().then((result: boolean) => {
console.info('Succeeded in pausing the download task.'); console.info('Succeeded in pausing the download task.');
}).catch((err) => { }).catch((err: BusinessError) => {
console.error(`Failed to pause the download task. Code: ${err.code}, message: ${err.message}`); console.error(`Failed to pause the download task. Code: ${err.code}, message: ${err.message}`);
}); });
``` ```
...@@ -1248,9 +1246,9 @@ suspend(callback: AsyncCallback&lt;boolean&gt;): void ...@@ -1248,9 +1246,9 @@ suspend(callback: AsyncCallback&lt;boolean&gt;): void
**示例:** **示例:**
```js ```ts
downloadTask.suspend((err, result)=>{ downloadTask.suspend((err: BusinessError, result: boolean) => {
if(err) { if (err) {
console.error(`Failed to pause the download task. Code: ${err.code}, message: ${err.message}`); console.error(`Failed to pause the download task. Code: ${err.code}, message: ${err.message}`);
return; return;
} }
...@@ -1277,10 +1275,10 @@ restore(): Promise&lt;boolean&gt; ...@@ -1277,10 +1275,10 @@ restore(): Promise&lt;boolean&gt;
**示例:** **示例:**
```js ```ts
downloadTask.restore().then((result) => { downloadTask.restore().then((result: boolean) => {
console.info('Succeeded in resuming the download task.') console.info('Succeeded in resuming the download task.')
}).catch((err) => { }).catch((err: BusinessError) => {
console.error(`Failed to resume the download task. Code: ${err.code}, message: ${err.message}`); console.error(`Failed to resume the download task. Code: ${err.code}, message: ${err.message}`);
}); });
``` ```
...@@ -1304,12 +1302,12 @@ restore(callback: AsyncCallback&lt;boolean&gt;): void ...@@ -1304,12 +1302,12 @@ restore(callback: AsyncCallback&lt;boolean&gt;): void
**示例:** **示例:**
```js ```ts
downloadTask.restore((err, result)=>{ downloadTask.restore((err: BusinessError, result: boolean) => {
if (err) { if (err) {
console.error(`Failed to resume the download task. Code: ${err.code}, message: ${err.message}`); console.error(`Failed to resume the download task. Code: ${err.code}, message: ${err.message}`);
return; return;
} }
console.info('Succeeded in resuming the download task.'); console.info('Succeeded in resuming the download task.');
}); });
``` ```
...@@ -1874,17 +1872,16 @@ on(event: 'progress', callback: (progress: Progress) =&gt; void): void ...@@ -1874,17 +1872,16 @@ on(event: 'progress', callback: (progress: Progress) =&gt; void): void
**示例:** **示例:**
```js ```ts
let context; let attachments: Array<request.agent.FormItem> = [{
let attachments = [{ name: "taskOnTest",
name: "taskOnTest", value: {
value: { filename: "taskOnTest.avi",
filename: "taskOnTest.avi", mimeType: "application/octet-stream",
mimetype: "application/octet-stream", path: "./taskOnTest.avi",
path: "./taskOnTest.avi", }
} }];
}]; let config: request.agent.Config = {
let config = {
action: request.agent.Action.UPLOAD, action: request.agent.Action.UPLOAD,
url: 'http://127.0.0.1', url: 'http://127.0.0.1',
title: 'taskOnTest', title: 'taskOnTest',
...@@ -1906,13 +1903,13 @@ on(event: 'progress', callback: (progress: Progress) =&gt; void): void ...@@ -1906,13 +1903,13 @@ on(event: 'progress', callback: (progress: Progress) =&gt; void): void
precise: false, precise: false,
token: "it is a secret" token: "it is a secret"
}; };
let createOnCallback = (progress) => { let createOnCallback = (progress: request.agent.Progress) => {
console.info('upload task completed.'); console.info('upload task progress.');
}; };
request.agent.create(context, config).then((task)=> { request.agent.create(this.context, config).then((task: request.agent.Task) => {
task.on('progress', createOnCallback); task.on('progress', createOnCallback);
console.info(`Succeeded in creating a upload task. result: ${task.tid}`); console.info(`Succeeded in creating a upload task. result: ${task.tid}`);
}).catch((err) => { }).catch((err: BusinessError) => {
console.error(`Failed to create a upload task, Code: ${err.code}, message: ${err.message}`); console.error(`Failed to create a upload task, Code: ${err.code}, message: ${err.message}`);
}); });
``` ```
...@@ -1946,17 +1943,16 @@ on(event: 'completed', callback: (progress: Progress) =&gt; void): void ...@@ -1946,17 +1943,16 @@ on(event: 'completed', callback: (progress: Progress) =&gt; void): void
**示例:** **示例:**
```js ```ts
let context; let attachments: Array<request.agent.FormItem> = [{
let attachments = [{ name: "taskOnTest",
name: "taskOnTest", value: {
value: { filename: "taskOnTest.avi",
filename: "taskOnTest.avi", mimeType: "application/octet-stream",
mimetype: "application/octet-stream", path: "./taskOnTest.avi",
path: "./taskOnTest.avi", }
} }];
}]; let config: request.agent.Config = {
let config = {
action: request.agent.Action.UPLOAD, action: request.agent.Action.UPLOAD,
url: 'http://127.0.0.1', url: 'http://127.0.0.1',
title: 'taskOnTest', title: 'taskOnTest',
...@@ -1978,13 +1974,13 @@ on(event: 'completed', callback: (progress: Progress) =&gt; void): void ...@@ -1978,13 +1974,13 @@ on(event: 'completed', callback: (progress: Progress) =&gt; void): void
precise: false, precise: false,
token: "it is a secret" token: "it is a secret"
}; };
let createOnCallback = (progress) => { let createOnCallback = (progress: request.agent.Progress) => {
console.info('upload task completed.'); console.info('upload task completed.');
}; };
request.agent.create(context, config).then((task)=> { request.agent.create(this.context, config).then((task: request.agent.Task) => {
task.on('completed', createOnCallback); task.on('completed', createOnCallback);
console.info(`Succeeded in creating a upload task. result: ${task.tid}`); console.info(`Succeeded in creating a upload task. result: ${task.tid}`);
}).catch((err) => { }).catch((err: BusinessError) => {
console.error(`Failed to create a upload task, Code: ${err.code}, message: ${err.message}`); console.error(`Failed to create a upload task, Code: ${err.code}, message: ${err.message}`);
}); });
``` ```
...@@ -2018,17 +2014,16 @@ on(event: 'failed', callback: (progress: Progress) =&gt; void): void ...@@ -2018,17 +2014,16 @@ on(event: 'failed', callback: (progress: Progress) =&gt; void): void
**示例:** **示例:**
```js ```ts
let context; let attachments: Array<request.agent.FormItem> = [{
let attachments = [{ name: "taskOnTest",
name: "taskOnTest", value: {
value: { filename: "taskOnTest.avi",
filename: "taskOnTest.avi", mimeType: "application/octet-stream",
mimetype: "application/octet-stream", path: "./taskOnTest.avi",
path: "./taskOnTest.avi", }
} }];
}]; let config: request.agent.Config = {
let config = {
action: request.agent.Action.UPLOAD, action: request.agent.Action.UPLOAD,
url: 'http://127.0.0.1', url: 'http://127.0.0.1',
title: 'taskOnTest', title: 'taskOnTest',
...@@ -2050,13 +2045,13 @@ on(event: 'failed', callback: (progress: Progress) =&gt; void): void ...@@ -2050,13 +2045,13 @@ on(event: 'failed', callback: (progress: Progress) =&gt; void): void
precise: false, precise: false,
token: "it is a secret" token: "it is a secret"
}; };
let createOnCallback = (progress) => { let createOnCallback = (progress: request.agent.Progress) => {
console.info('upload task completed.'); console.info('upload task failed.');
}; };
request.agent.create(context, config).then((task)=> { request.agent.create(this.context, config).then((task: request.agent.Task) => {
task.on('failed', createOnCallback); task.on('failed', createOnCallback);
console.info(`Succeeded in creating a upload task. result: ${task.tid}`); console.info(`Succeeded in creating a upload task. result: ${task.tid}`);
}).catch((err) => { }).catch((err: BusinessError) => {
console.error(`Failed to create a upload task, Code: ${err.code}, message: ${err.message}`); console.error(`Failed to create a upload task, Code: ${err.code}, message: ${err.message}`);
}); });
``` ```
...@@ -2091,17 +2086,16 @@ off(event: 'progress', callback?: (progress: Progress) =&gt; void): void ...@@ -2091,17 +2086,16 @@ off(event: 'progress', callback?: (progress: Progress) =&gt; void): void
**示例:** **示例:**
```js ```ts
let context; let attachments: Array<request.agent.FormItem> = [{
let attachments = [{ name: "taskOffTest",
name: "taskOffTest", value: {
value: { filename: "taskOffTest.avi",
filename: "taskOffTest.avi", mimeType: "application/octet-stream",
mimetype: "application/octet-stream", path: "./taskOffTest.avi",
path: "./taskOffTest.avi", }
} }];
}]; let config: request.agent.Config = {
let config = {
action: request.agent.Action.UPLOAD, action: request.agent.Action.UPLOAD,
url: 'http://127.0.0.1', url: 'http://127.0.0.1',
title: 'taskOffTest', title: 'taskOffTest',
...@@ -2123,14 +2117,14 @@ off(event: 'progress', callback?: (progress: Progress) =&gt; void): void ...@@ -2123,14 +2117,14 @@ off(event: 'progress', callback?: (progress: Progress) =&gt; void): void
precise: false, precise: false,
token: "it is a secret" token: "it is a secret"
}; };
let createOffCallback = (progress) => { let createOffCallback = (progress: request.agent.Progress) => {
console.info('upload task completed.'); console.info('upload task progress.');
}; };
request.agent.create(context, config).then((task)=> { request.agent.create(this.context, config).then((task: request.agent.Task) => {
task.on('progress', createOffCallback); task.on('progress', createOffCallback);
task.off('progress', createOffCallback); task.off('progress', createOffCallback);
console.info(`Succeeded in creating a upload task. result: ${task.tid}`); console.info(`Succeeded in creating a upload task. result: ${task.tid}`);
}).catch((err) => { }).catch((err: BusinessError) => {
console.error(`Failed to create a upload task, Code: ${err.code}, message: ${err.message}`); console.error(`Failed to create a upload task, Code: ${err.code}, message: ${err.message}`);
}); });
``` ```
...@@ -2164,17 +2158,16 @@ off(event: 'completed', callback?: (progress: Progress) =&gt; void): void ...@@ -2164,17 +2158,16 @@ off(event: 'completed', callback?: (progress: Progress) =&gt; void): void
**示例:** **示例:**
```js ```ts
let context; let attachments: Array<request.agent.FormItem> = [{
let attachments = [{ name: "taskOffTest",
name: "taskOffTest", value: {
value: { filename: "taskOffTest.avi",
filename: "taskOffTest.avi", mimeType: "application/octet-stream",
mimetype: "application/octet-stream", path: "./taskOffTest.avi",
path: "./taskOffTest.avi", }
} }];
}]; let config: request.agent.Config = {
let config = {
action: request.agent.Action.UPLOAD, action: request.agent.Action.UPLOAD,
url: 'http://127.0.0.1', url: 'http://127.0.0.1',
title: 'taskOffTest', title: 'taskOffTest',
...@@ -2196,14 +2189,14 @@ off(event: 'completed', callback?: (progress: Progress) =&gt; void): void ...@@ -2196,14 +2189,14 @@ off(event: 'completed', callback?: (progress: Progress) =&gt; void): void
precise: false, precise: false,
token: "it is a secret" token: "it is a secret"
}; };
let createOffCallback = (progress) => { let createOffCallback = (progress: request.agent.Progress) => {
console.info('upload task completed.'); console.info('upload task completed.');
}; };
request.agent.create(context, config).then((task)=> { request.agent.create(this.context, config).then((task: request.agent.Task) => {
task.on('completed', createOffCallback); task.on('completed', createOffCallback);
task.off('completed', createOffCallback); task.off('completed', createOffCallback);
console.info(`Succeeded in creating a upload task. result: ${task.tid}`); console.info(`Succeeded in creating a upload task. result: ${task.tid}`);
}).catch((err) => { }).catch((err: BusinessError) => {
console.error(`Failed to create a upload task, Code: ${err.code}, message: ${err.message}`); console.error(`Failed to create a upload task, Code: ${err.code}, message: ${err.message}`);
}); });
``` ```
...@@ -2237,17 +2230,16 @@ off(event: 'failed', callback?: (progress: Progress) =&gt; void): void ...@@ -2237,17 +2230,16 @@ off(event: 'failed', callback?: (progress: Progress) =&gt; void): void
**示例:** **示例:**
```js ```ts
let context; let attachments: Array<request.agent.FormItem> = [{
let attachments = [{ name: "taskOffTest",
name: "taskOffTest", value: {
value: { filename: "taskOffTest.avi",
filename: "taskOffTest.avi", mimeType: "application/octet-stream",
mimetype: "application/octet-stream", path: "./taskOffTest.avi",
path: "./taskOffTest.avi", }
} }];
}]; let config: request.agent.Config = {
let config = {
action: request.agent.Action.UPLOAD, action: request.agent.Action.UPLOAD,
url: 'http://127.0.0.1', url: 'http://127.0.0.1',
title: 'taskOffTest', title: 'taskOffTest',
...@@ -2269,14 +2261,14 @@ off(event: 'failed', callback?: (progress: Progress) =&gt; void): void ...@@ -2269,14 +2261,14 @@ off(event: 'failed', callback?: (progress: Progress) =&gt; void): void
precise: false, precise: false,
token: "it is a secret" token: "it is a secret"
}; };
let createOffCallback = (progress) => { let createOffCallback = (progress: request.agent.Progress) => {
console.info('upload task completed.'); console.info('upload task failed.');
}; };
request.agent.create(context, config).then((task)=> { request.agent.create(this.context, config).then((task: request.agent.Task) => {
task.on('failed', createOffCallback); task.on('failed', createOffCallback);
task.off('failed', createOffCallback); task.off('failed', createOffCallback);
console.info(`Succeeded in creating a upload task. result: ${task.tid}`); console.info(`Succeeded in creating a upload task. result: ${task.tid}`);
}).catch((err) => { }).catch((err: BusinessError) => {
console.error(`Failed to create a upload task, Code: ${err.code}, message: ${err.message}`); console.error(`Failed to create a upload task, Code: ${err.code}, message: ${err.message}`);
}); });
``` ```
...@@ -2312,9 +2304,8 @@ start(callback: AsyncCallback&lt;void&gt;): void ...@@ -2312,9 +2304,8 @@ start(callback: AsyncCallback&lt;void&gt;): void
**示例:** **示例:**
```js ```ts
let context; let config: request.agent.Config = {
let config = {
action: request.agent.Action.DOWNLOAD, action: request.agent.Action.DOWNLOAD,
url: 'http://127.0.0.1', url: 'http://127.0.0.1',
title: 'taskStartTest', title: 'taskStartTest',
...@@ -2336,8 +2327,8 @@ start(callback: AsyncCallback&lt;void&gt;): void ...@@ -2336,8 +2327,8 @@ start(callback: AsyncCallback&lt;void&gt;): void
precise: false, precise: false,
token: "it is a secret" token: "it is a secret"
}; };
request.agent.create(context, config).then((task) => { request.agent.create(this.context, config).then((task: request.agent.Task) => {
task.start((err) => { task.start((err: BusinessError) => {
if (err) { if (err) {
console.error(`Failed to start the download task, Code: ${err.code}, message: ${err.message}`); console.error(`Failed to start the download task, Code: ${err.code}, message: ${err.message}`);
return; return;
...@@ -2345,7 +2336,7 @@ start(callback: AsyncCallback&lt;void&gt;): void ...@@ -2345,7 +2336,7 @@ start(callback: AsyncCallback&lt;void&gt;): void
console.info(`Succeeded in starting a download task.`); console.info(`Succeeded in starting a download task.`);
}); });
console.info(`Succeeded in creating a download task. result: ${task.tid}`); console.info(`Succeeded in creating a download task. result: ${task.tid}`);
}).catch((err) => { }).catch((err: BusinessError) => {
console.error(`Failed to create a download task, Code: ${err.code}, message: ${err.message}`); console.error(`Failed to create a download task, Code: ${err.code}, message: ${err.message}`);
}); });
``` ```
...@@ -2381,9 +2372,8 @@ start(): Promise&lt;void&gt; ...@@ -2381,9 +2372,8 @@ start(): Promise&lt;void&gt;
**示例:** **示例:**
```js ```ts
let context; let config: request.agent.Config = {
let config = {
action: request.agent.Action.DOWNLOAD, action: request.agent.Action.DOWNLOAD,
url: 'http://127.0.0.1', url: 'http://127.0.0.1',
title: 'taskStartTest', title: 'taskStartTest',
...@@ -2405,14 +2395,14 @@ start(): Promise&lt;void&gt; ...@@ -2405,14 +2395,14 @@ start(): Promise&lt;void&gt;
precise: false, precise: false,
token: "it is a secret" token: "it is a secret"
}; };
request.agent.create(context, config).then((task) => { request.agent.create(this.context, config).then((task: request.agent.Task) => {
task.start().then(() => { task.start().then(() => {
console.info(`Succeeded in starting a download task.`); console.info(`Succeeded in starting a download task.`);
}).catch((err) => { }).catch((err: BusinessError) => {
console.error(`Failed to start the download task, Code: ${err.code}, message: ${err.message}`); console.error(`Failed to start the download task, Code: ${err.code}, message: ${err.message}`);
}); });
console.info(`Succeeded in creating a download task. result: ${task.tid}`); console.info(`Succeeded in creating a download task. result: ${task.tid}`);
}).catch((err) => { }).catch((err: BusinessError) => {
console.error(`Failed to create a download task, Code: ${err.code}, message: ${err.message}`); console.error(`Failed to create a download task, Code: ${err.code}, message: ${err.message}`);
}); });
``` ```
...@@ -2447,9 +2437,8 @@ pause(callback: AsyncCallback&lt;void&gt;): void ...@@ -2447,9 +2437,8 @@ pause(callback: AsyncCallback&lt;void&gt;): void
**示例:** **示例:**
```js ```ts
let context; let config: request.agent.Config = {
let config = {
action: request.agent.Action.DOWNLOAD, action: request.agent.Action.DOWNLOAD,
url: 'http://127.0.0.1', url: 'http://127.0.0.1',
title: 'taskPauseTest', title: 'taskPauseTest',
...@@ -2471,8 +2460,8 @@ pause(callback: AsyncCallback&lt;void&gt;): void ...@@ -2471,8 +2460,8 @@ pause(callback: AsyncCallback&lt;void&gt;): void
precise: false, precise: false,
token: "it is a secret" token: "it is a secret"
}; };
request.agent.create(context, config).then((task) => { request.agent.create(this.context, config).then((task: request.agent.Task) => {
task.pause((err) => { task.pause((err: BusinessError) => {
if (err) { if (err) {
console.error(`Failed to pause the download task, Code: ${err.code}, message: ${err.message}`); console.error(`Failed to pause the download task, Code: ${err.code}, message: ${err.message}`);
return; return;
...@@ -2480,7 +2469,7 @@ pause(callback: AsyncCallback&lt;void&gt;): void ...@@ -2480,7 +2469,7 @@ pause(callback: AsyncCallback&lt;void&gt;): void
console.info(`Succeeded in pausing a download task. `); console.info(`Succeeded in pausing a download task. `);
}); });
console.info(`Succeeded in creating a download task. result: ${task.tid}`); console.info(`Succeeded in creating a download task. result: ${task.tid}`);
}).catch((err) => { }).catch((err: BusinessError) => {
console.error(`Failed to create a download task, Code: ${err.code}, message: ${err.message}`); console.error(`Failed to create a download task, Code: ${err.code}, message: ${err.message}`);
}); });
``` ```
...@@ -2512,9 +2501,8 @@ pause(): Promise&lt;void&gt; ...@@ -2512,9 +2501,8 @@ pause(): Promise&lt;void&gt;
**示例:** **示例:**
```js ```ts
let context; let config: request.agent.Config = {
let config = {
action: request.agent.Action.DOWNLOAD, action: request.agent.Action.DOWNLOAD,
url: 'http://127.0.0.1', url: 'http://127.0.0.1',
title: 'taskPauseTest', title: 'taskPauseTest',
...@@ -2536,14 +2524,14 @@ pause(): Promise&lt;void&gt; ...@@ -2536,14 +2524,14 @@ pause(): Promise&lt;void&gt;
precise: false, precise: false,
token: "it is a secret" token: "it is a secret"
}; };
request.agent.create(context, config).then((task) => { request.agent.create(this.context, config).then((task: request.agent.Task) => {
task.pause().then(() => { task.pause().then(() => {
console.info(`Succeeded in pausing a download task. `); console.info(`Succeeded in pausing a download task. `);
}).catch((err) => { }).catch((err: BusinessError) => {
console.error(`Failed to pause the upload task, Code: ${err.code}, message: ${err.message}`); console.error(`Failed to pause the upload task, Code: ${err.code}, message: ${err.message}`);
}); });
console.info(`Succeeded in creating a download task. result: ${task.tid}`); console.info(`Succeeded in creating a download task. result: ${task.tid}`);
}).catch((err) => { }).catch((err: BusinessError) => {
console.error(`Failed to create a upload task, Code: ${err.code}, message: ${err.message}`); console.error(`Failed to create a upload task, Code: ${err.code}, message: ${err.message}`);
}); });
``` ```
...@@ -2577,9 +2565,8 @@ resume(callback: AsyncCallback&lt;void&gt;): void ...@@ -2577,9 +2565,8 @@ resume(callback: AsyncCallback&lt;void&gt;): void
**示例:** **示例:**
```js ```ts
let context; let config: request.agent.Config = {
let config = {
action: request.agent.Action.DOWNLOAD, action: request.agent.Action.DOWNLOAD,
url: 'http://127.0.0.1', url: 'http://127.0.0.1',
title: 'taskResumeTest', title: 'taskResumeTest',
...@@ -2601,8 +2588,8 @@ resume(callback: AsyncCallback&lt;void&gt;): void ...@@ -2601,8 +2588,8 @@ resume(callback: AsyncCallback&lt;void&gt;): void
precise: false, precise: false,
token: "it is a secret" token: "it is a secret"
}; };
request.agent.create(context, config).then((task) => { request.agent.create(this.context, config).then((task: request.agent.Task) => {
task.resume((err) => { task.resume((err: BusinessError) => {
if (err) { if (err) {
console.error(`Failed to resume the download task, Code: ${err.code}, message: ${err.message}`); console.error(`Failed to resume the download task, Code: ${err.code}, message: ${err.message}`);
return; return;
...@@ -2610,7 +2597,7 @@ resume(callback: AsyncCallback&lt;void&gt;): void ...@@ -2610,7 +2597,7 @@ resume(callback: AsyncCallback&lt;void&gt;): void
console.info(`Succeeded in resuming a download task. `); console.info(`Succeeded in resuming a download task. `);
}); });
console.info(`Succeeded in creating a download task. result: ${task.tid}`); console.info(`Succeeded in creating a download task. result: ${task.tid}`);
}).catch((err) => { }).catch((err: BusinessError) => {
console.error(`Failed to create a download task, Code: ${err.code}, message: ${err.message}`); console.error(`Failed to create a download task, Code: ${err.code}, message: ${err.message}`);
}); });
``` ```
...@@ -2644,9 +2631,8 @@ resume(): Promise&lt;void&gt; ...@@ -2644,9 +2631,8 @@ resume(): Promise&lt;void&gt;
**示例:** **示例:**
```js ```ts
let context; let config: request.agent.Config = {
let config = {
action: request.agent.Action.DOWNLOAD, action: request.agent.Action.DOWNLOAD,
url: 'http://127.0.0.1', url: 'http://127.0.0.1',
title: 'taskResumeTest', title: 'taskResumeTest',
...@@ -2668,14 +2654,14 @@ resume(): Promise&lt;void&gt; ...@@ -2668,14 +2654,14 @@ resume(): Promise&lt;void&gt;
precise: false, precise: false,
token: "it is a secret" token: "it is a secret"
}; };
request.agent.create(context, config).then((task) => { request.agent.create(this.context, config).then((task: request.agent.Task) => {
task.resume().then(() => { task.resume().then(() => {
console.info(`Succeeded in resuming a download task. `); console.info(`Succeeded in resuming a download task. `);
}).catch((err) => { }).catch((err: BusinessError) => {
console.error(`Failed to resume the download task, Code: ${err.code}, message: ${err.message}`); console.error(`Failed to resume the download task, Code: ${err.code}, message: ${err.message}`);
}); });
console.info(`Succeeded in creating a download task. result: ${task.tid}`); console.info(`Succeeded in creating a download task. result: ${task.tid}`);
}).catch((err) => { }).catch((err: BusinessError) => {
console.error(`Failed to create a download task, Code: ${err.code}, message: ${err.message}`); console.error(`Failed to create a download task, Code: ${err.code}, message: ${err.message}`);
}); });
``` ```
...@@ -2706,9 +2692,8 @@ stop(callback: AsyncCallback&lt;void&gt;): void ...@@ -2706,9 +2692,8 @@ stop(callback: AsyncCallback&lt;void&gt;): void
**示例:** **示例:**
```js ```ts
let context; let config: request.agent.Config = {
let config = {
action: request.agent.Action.DOWNLOAD, action: request.agent.Action.DOWNLOAD,
url: 'http://127.0.0.1', url: 'http://127.0.0.1',
title: 'taskStopTest', title: 'taskStopTest',
...@@ -2730,8 +2715,8 @@ stop(callback: AsyncCallback&lt;void&gt;): void ...@@ -2730,8 +2715,8 @@ stop(callback: AsyncCallback&lt;void&gt;): void
precise: false, precise: false,
token: "it is a secret" token: "it is a secret"
}; };
request.agent.create(context, config).then((task) => { request.agent.create(this.context, config).then((task: request.agent.Task) => {
task.stop((err) => { task.stop((err: BusinessError) => {
if (err) { if (err) {
console.error(`Failed to stop the download task, Code: ${err.code}, message: ${err.message}`); console.error(`Failed to stop the download task, Code: ${err.code}, message: ${err.message}`);
return; return;
...@@ -2739,7 +2724,7 @@ stop(callback: AsyncCallback&lt;void&gt;): void ...@@ -2739,7 +2724,7 @@ stop(callback: AsyncCallback&lt;void&gt;): void
console.info(`Succeeded in stopping a download task. `); console.info(`Succeeded in stopping a download task. `);
}); });
console.info(`Succeeded in creating a download task. result: ${task.tid}`); console.info(`Succeeded in creating a download task. result: ${task.tid}`);
}).catch((err) => { }).catch((err: BusinessError) => {
console.error(`Failed to create a download task, Code: ${err.code}, message: ${err.message}`); console.error(`Failed to create a download task, Code: ${err.code}, message: ${err.message}`);
}); });
``` ```
...@@ -2770,9 +2755,8 @@ stop(): Promise&lt;void&gt; ...@@ -2770,9 +2755,8 @@ stop(): Promise&lt;void&gt;
**示例:** **示例:**
```js ```ts
let context; let config: request.agent.Config = {
let config = {
action: request.agent.Action.DOWNLOAD, action: request.agent.Action.DOWNLOAD,
url: 'http://127.0.0.1', url: 'http://127.0.0.1',
title: 'taskStopTest', title: 'taskStopTest',
...@@ -2794,14 +2778,14 @@ stop(): Promise&lt;void&gt; ...@@ -2794,14 +2778,14 @@ stop(): Promise&lt;void&gt;
precise: false, precise: false,
token: "it is a secret" token: "it is a secret"
}; };
request.agent.create(context, config).then((task) => { request.agent.create(this.context, config).then((task: request.agent.Task) => {
task.stop().then(() => { task.stop().then(() => {
console.info(`Succeeded in stopping a download task. `); console.info(`Succeeded in stopping a download task. `);
}).catch((err) => { }).catch((err: BusinessError) => {
console.error(`Failed to stop the download task, Code: ${err.code}, message: ${err.message}`); console.error(`Failed to stop the download task, Code: ${err.code}, message: ${err.message}`);
}); });
console.info(`Succeeded in creating a download task. result: ${task.tid}`); console.info(`Succeeded in creating a download task. result: ${task.tid}`);
}).catch((err) => { }).catch((err: BusinessError) => {
console.error(`Failed to create a download task, Code: ${err.code}, message: ${err.message}`); console.error(`Failed to create a download task, Code: ${err.code}, message: ${err.message}`);
}); });
``` ```
...@@ -2838,17 +2822,16 @@ create(context: BaseContext, config: Config, callback: AsyncCallback&lt;Task&gt; ...@@ -2838,17 +2822,16 @@ create(context: BaseContext, config: Config, callback: AsyncCallback&lt;Task&gt;
**示例:** **示例:**
```js ```ts
let context; let attachments: Array<request.agent.FormItem> = [{
let attachments = [{ name: "reeateTest",
name: "reeateTest", value: {
value: { filename: "reeateTest.avi",
filename: "reeateTest.avi", mimeType: "application/octet-stream",
mimetype: "application/octet-stream", path: "./reeateTest.avi",
path: "./reeateTest.avi", }
} }];
}]; let config: request.agent.Config = {
let config = {
action: request.agent.Action.UPLOAD, action: request.agent.Action.UPLOAD,
url: 'http://127.0.0.1', url: 'http://127.0.0.1',
title: 'reeateTest', title: 'reeateTest',
...@@ -2870,7 +2853,7 @@ create(context: BaseContext, config: Config, callback: AsyncCallback&lt;Task&gt; ...@@ -2870,7 +2853,7 @@ create(context: BaseContext, config: Config, callback: AsyncCallback&lt;Task&gt;
precise: false, precise: false,
token: "it is a secret" token: "it is a secret"
}; };
request.agent.create(context, config, (err, task) => { request.agent.create(this.context, config, (err: BusinessError, task: request.agent.Task) => {
if (err) { if (err) {
console.error(`Failed to create a download task, Code: ${err.code}, message: ${err.message}`); console.error(`Failed to create a download task, Code: ${err.code}, message: ${err.message}`);
return; return;
...@@ -2920,17 +2903,16 @@ create(context: BaseContext, config: Config): Promise&lt;Task&gt; ...@@ -2920,17 +2903,16 @@ create(context: BaseContext, config: Config): Promise&lt;Task&gt;
**示例:** **示例:**
```js ```ts
let context; let attachments: Array<request.agent.FormItem> = [{
let attachments = [{ name: "reeateTest",
name: "reeateTest", value: {
value: { filename: "reeateTest.avi",
filename: "reeateTest.avi", mimeType: "application/octet-stream",
mimetype: "application/octet-stream", path: "./reeateTest.avi",
path: "./reeateTest.avi", }
} }];
}]; let config: request.agent.Config = {
let config = {
action: request.agent.Action.UPLOAD, action: request.agent.Action.UPLOAD,
url: 'http://127.0.0.1', url: 'http://127.0.0.1',
title: 'reeateTest', title: 'reeateTest',
...@@ -2952,7 +2934,7 @@ create(context: BaseContext, config: Config): Promise&lt;Task&gt; ...@@ -2952,7 +2934,7 @@ create(context: BaseContext, config: Config): Promise&lt;Task&gt;
precise: false, precise: false,
token: "it is a secret" token: "it is a secret"
}; };
request.agent.create(context, config).then((task)=> { request.agent.create(this.context, config).then((task: request.agent.Task) => {
console.info(`Succeeded in creating a download task. result: ${task.config}`); console.info(`Succeeded in creating a download task. result: ${task.config}`);
}).catch((err) => { }).catch((err) => {
console.error(`Failed to create a download task, Code: ${err.code}, message: ${err.message}`); console.error(`Failed to create a download task, Code: ${err.code}, message: ${err.message}`);
...@@ -2989,8 +2971,8 @@ remove(id: string, callback: AsyncCallback&lt;void&gt;): void ...@@ -2989,8 +2971,8 @@ remove(id: string, callback: AsyncCallback&lt;void&gt;): void
**示例:** **示例:**
```js ```ts
request.agent.remove("id", (err) => { request.agent.remove("id", (err: BusinessError) => {
if (err) { if (err) {
console.error(`Failed to removing a download task, Code: ${err.code}, message: ${err.message}`); console.error(`Failed to removing a download task, Code: ${err.code}, message: ${err.message}`);
return; return;
...@@ -3031,10 +3013,10 @@ remove(id: string): Promise&lt;void&gt; ...@@ -3031,10 +3013,10 @@ remove(id: string): Promise&lt;void&gt;
**示例:** **示例:**
```js ```ts
request.agent.remove("id").then(() => { request.agent.remove("id").then(() => {
console.info(`Succeeded in removing a download task. `); console.info(`Succeeded in removing a download task. `);
}).catch((err) => { }).catch((err: BusinessError) => {
console.error(`Failed to remove a download task, Code: ${err.code}, message: ${err.message}`); console.error(`Failed to remove a download task, Code: ${err.code}, message: ${err.message}`);
}); });
``` ```
...@@ -3065,8 +3047,8 @@ show(id: string, callback: AsyncCallback&lt;TaskInfo&gt;): void ...@@ -3065,8 +3047,8 @@ show(id: string, callback: AsyncCallback&lt;TaskInfo&gt;): void
**示例:** **示例:**
```js ```ts
request.agent.show("123456", (err, TaskInfo) => { request.agent.show("123456", (err: BusinessError, taskInfo: request.agent.TaskInfo) => {
if (err) { if (err) {
console.error(`Failed to show a unload task, Code: ${err.code}, message: ${err.message}`); console.error(`Failed to show a unload task, Code: ${err.code}, message: ${err.message}`);
return; return;
...@@ -3106,10 +3088,10 @@ show(id: string): Promise&lt;TaskInfo&gt; ...@@ -3106,10 +3088,10 @@ show(id: string): Promise&lt;TaskInfo&gt;
**示例:** **示例:**
```js ```ts
request.agent.show("123456").then((TaskInfo) => { request.agent.show("123456").then((taskInfo: request.agent.TaskInfo) => {
console.info(`Succeeded in showing a unload task.`); console.info(`Succeeded in showing a unload task.`);
}).catch((err) => { }).catch((err: BusinessError) => {
console.error(`Failed to show a unload task, Code: ${err.code}, message: ${err.message}`); console.error(`Failed to show a unload task, Code: ${err.code}, message: ${err.message}`);
}); });
``` ```
...@@ -3141,8 +3123,8 @@ touch(id: string, token: string, callback: AsyncCallback&lt;TaskInfo&gt;): void ...@@ -3141,8 +3123,8 @@ touch(id: string, token: string, callback: AsyncCallback&lt;TaskInfo&gt;): void
**示例:** **示例:**
```js ```ts
request.agent.touch("123456", "token", (err, TaskInfo) => { request.agent.touch("123456", "token", (err: BusinessError, taskInfo: request.agent.TaskInfo) => {
if (err) { if (err) {
console.error(`Failed to touch a unload task, Code: ${err.code}, message: ${err.message}`); console.error(`Failed to touch a unload task, Code: ${err.code}, message: ${err.message}`);
return; return;
...@@ -3183,10 +3165,10 @@ touch(id: string, token: string): Promise&lt;TaskInfo&gt; ...@@ -3183,10 +3165,10 @@ touch(id: string, token: string): Promise&lt;TaskInfo&gt;
**示例:** **示例:**
```js ```ts
request.agent.touch("123456", "token").then((TaskInfo) => { request.agent.touch("123456", "token").then((taskInfo: request.agent.TaskInfo) => {
console.info(`Succeeded in touching a unload task. `); console.info(`Succeeded in touching a unload task. `);
}).catch((err) => { }).catch((err: BusinessError) => {
console.error(`Failed to touch a unload task, Code: ${err.code}, message: ${err.message}`); console.error(`Failed to touch a unload task, Code: ${err.code}, message: ${err.message}`);
}); });
``` ```
...@@ -3216,13 +3198,13 @@ search(filter: Filter, callback: AsyncCallback&lt;Array&lt;string&gt;&gt;): void ...@@ -3216,13 +3198,13 @@ search(filter: Filter, callback: AsyncCallback&lt;Array&lt;string&gt;&gt;): void
**示例:** **示例:**
```js ```ts
let filter ={ let filter: request.agent.Filter = {
bundle:"com.example.myapplication", bundle: "com.example.myapplication",
action: request.agent.Action.UPLOAD, action: request.agent.Action.UPLOAD,
mode:request.agent.Mode.BACKGROUND mode: request.agent.Mode.BACKGROUND
} }
request.agent.search(filter, (err, data) => { request.agent.search(filter, (err: BusinessError, data: Array<string>) => {
if (err) { if (err) {
console.error(`Failed to search a unload task, Code: ${err.code}, message: ${err.message}`); console.error(`Failed to search a unload task, Code: ${err.code}, message: ${err.message}`);
return; return;
...@@ -3261,15 +3243,15 @@ search(filter: Filter): Promise&lt;Array&lt;string&gt;&gt; ...@@ -3261,15 +3243,15 @@ search(filter: Filter): Promise&lt;Array&lt;string&gt;&gt;
**示例:** **示例:**
```js ```ts
let filter ={ let filter: request.agent.Filter = {
bundle:"com.example.myapplication", bundle: "com.example.myapplication",
action: request.agent.Action.UPLOAD, action: request.agent.Action.UPLOAD,
mode: request.agent.Mode.BACKGROUND mode: request.agent.Mode.BACKGROUND
} }
request.agent.search(filter).then((data) => { request.agent.search(filter).then((data: Array<string>) => {
console.info(`Succeeded in searching a unload task. `); console.info(`Succeeded in searching a unload task. `);
}).catch((err) => { }).catch((err: BusinessError) => {
console.error(`Failed to search a unload task, Code: ${err.code}, message: ${err.message}`); console.error(`Failed to search a unload task, Code: ${err.code}, message: ${err.message}`);
}); });
``` ```
...@@ -3304,13 +3286,13 @@ query(id: string, callback: AsyncCallback&lt;TaskInfo&gt;): void ...@@ -3304,13 +3286,13 @@ query(id: string, callback: AsyncCallback&lt;TaskInfo&gt;): void
**示例:** **示例:**
```js ```ts
request.agent.query("123456", (err, TaskInfo) => { request.agent.query("123456", (err: BusinessError, taskInfo: request.agent.TaskInfo) => {
if (err) { if (err) {
console.error(`Failed to query a unload task, Code: ${err.code}, message: ${err.message}`); console.error(`Failed to query a unload task, Code: ${err.code}, message: ${err.message}`);
return; return;
} }
console.info(`Succeeded in querying a unload task. result: ${TaskInfo.uid}`); console.info(`Succeeded in querying a unload task. result: ${taskInfo.uid}`);
}); });
``` ```
...@@ -3349,10 +3331,10 @@ query(id: string): Promise&lt;TaskInfo&gt; ...@@ -3349,10 +3331,10 @@ query(id: string): Promise&lt;TaskInfo&gt;
**示例:** **示例:**
```js ```ts
request.agent.query("123456",).then((TaskInfo) => { request.agent.query("123456",).then((taskInfo: request.agent.TaskInfo) => {
console.info(`Succeeded in querying a unload task. result: ${TaskInfo.uid}`); console.info(`Succeeded in querying a unload task. result: ${taskInfo.uid}`);
}).catch((err) => { }).catch((err: BusinessError) => {
console.error(`Failed to query a unload task, Code: ${err.code}, message: ${err.message}`); console.error(`Failed to query a unload task, Code: ${err.code}, message: ${err.message}`);
}); });
``` ```
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册