js-apis-ability-context.md 14.9 KB
Newer Older
W
wusongqing 已提交
1 2
# AbilityContext

3
> **NOTE**<br>
W
wusongqing 已提交
4
> The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version.
W
wusongqing 已提交
5 6


W
wusongqing 已提交
7
Implements the ability context. This module is inherited from **Context**.
W
wusongqing 已提交
8 9


W
wusongqing 已提交
10 11 12 13 14 15
## Usage


Before using the **AbilityContext** module, you must define a child class that inherits from **Ability**.


W
wusongqing 已提交
16

W
wusongqing 已提交
17
```js
W
wusongqing 已提交
18 19 20 21 22 23 24 25 26
import Ability from '@ohos.application.Ability'
class MainAbility extends Ability {
    onWindowStageCreate(windowStage) {
        let context = this.context;
    }
}
```


W
wusongqing 已提交
27
## Attributes
W
wusongqing 已提交
28

W
wusongqing 已提交
29 30
**System capability**: SystemCapability.Ability.AbilityRuntime.Core

31
| Name | Type | Readable | Writable | Description | 
W
wusongqing 已提交
32
| -------- | -------- | -------- | -------- | -------- |
W
wusongqing 已提交
33 34
| abilityInfo | AbilityInfo | Yes| No| Ability information.| 
| currentHapModuleInfo | HapModuleInfo | Yes| No| Information about the current HAP.| 
W
wusongqing 已提交
35 36


W
wusongqing 已提交
37
## AbilityContext.startAbility
W
wusongqing 已提交
38 39 40

startAbility(want: Want, callback: AsyncCallback&lt;void&gt;): void

W
wusongqing 已提交
41
Starts an ability. This API uses a callback to return the result.
W
wusongqing 已提交
42

W
wusongqing 已提交
43
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
W
wusongqing 已提交
44

W
wusongqing 已提交
45
**Parameters**
W
wusongqing 已提交
46

47
  | Name | Type | Mandatory | Description | 
W
wusongqing 已提交
48
  | -------- | -------- | -------- | -------- |
W
wusongqing 已提交
49
  | want | [Want](js-apis-application-Want.md) | Yes| Information about the **Want** used for starting an ability.| 
W
wusongqing 已提交
50
  | callback | AsyncCallback&lt;void&gt; | Yes| Callback used to return the result.| 
W
wusongqing 已提交
51

W
wusongqing 已提交
52 53 54
**Example**

  ```js
W
wusongqing 已提交
55 56 57 58 59 60 61 62 63 64 65
  var want = {
  	"deviceId": "",
  	"bundleName": "com.extreme.test",
  	"abilityName": "com.extreme.test.MainAbility"
  };
  this.context.startAbility(want, (error) => {
      console.log("error.code = " + error.code)
  })
  ```


W
wusongqing 已提交
66
## AbilityContext.startAbility
W
wusongqing 已提交
67

W
wusongqing 已提交
68 69
startAbility(want: Want, options: StartOptions, callback: AsyncCallback&lt;void&gt;): void

W
wusongqing 已提交
70
Starts an ability. This API uses a callback to return the result.
W
wusongqing 已提交
71

W
wusongqing 已提交
72
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
W
wusongqing 已提交
73

W
wusongqing 已提交
74
**Parameters**
W
wusongqing 已提交
75

76
  | Name | Type | Mandatory | Description | 
W
wusongqing 已提交
77
  | -------- | -------- | -------- | -------- |
W
wusongqing 已提交
78
  | want | [Want](js-apis-application-Want.md)  | Yes| Information about the **Want** used for starting an ability.| 
W
wusongqing 已提交
79 80 81
  | options | StartOptions | Yes| Parameters used for starting the ability.|
  | callback | AsyncCallback&lt;void&gt; | Yes| Callback used to return the result.| 

W
wusongqing 已提交
82
**Example**
W
wusongqing 已提交
83
    
W
wusongqing 已提交
84
  ```js
W
wusongqing 已提交
85 86 87 88 89 90 91 92 93 94 95 96 97 98
  var want = {
  	"deviceId": "",
  	"bundleName": "com.extreme.test",
  	"abilityName": "com.extreme.test.MainAbility"
  };
  var options = {
  	windowMode: 0,
  };
  this.context.startAbility(want, options, (error) => {
      console.log("error.code = " + error.code)
  })
  ```


W
wusongqing 已提交
99
## AbilityContext.startAbility
W
wusongqing 已提交
100

W
wusongqing 已提交
101
startAbility(want: Want, options?: StartOptions): Promise&lt;void&gt;;
W
wusongqing 已提交
102

W
wusongqing 已提交
103
Starts an ability. This API uses a promise to return the result.
W
wusongqing 已提交
104

W
wusongqing 已提交
105
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
W
wusongqing 已提交
106

W
wusongqing 已提交
107
**Parameters**
W
wusongqing 已提交
108

109
  | Name | Type | Mandatory | Description | 
W
wusongqing 已提交
110
  | -------- | -------- | -------- | -------- |
W
wusongqing 已提交
111
  | want | [Want](js-apis-application-Want.md) | Yes| Information about the **Want** used for starting an ability.| 
W
wusongqing 已提交
112 113 114
  | options | StartOptions | No| Parameters used for starting the ability.|

**Return value**
W
wusongqing 已提交
115

116
  | Type | Description | 
W
wusongqing 已提交
117
  | -------- | -------- |
W
wusongqing 已提交
118
  | Promise&lt;void&gt; | Promise used to return the result.| 
W
wusongqing 已提交
119

W
wusongqing 已提交
120 121 122
**Example**

  ```js
W
wusongqing 已提交
123 124 125 126 127
  var want = {
  	"deviceId": "",
  	"bundleName": "com.extreme.test",
  	"abilityName": "com.extreme.test.MainAbility"
  };
W
wusongqing 已提交
128 129 130 131
  var options = {
  	windowMode: 0,
  };
  this.context.startAbility(want, options)
W
wusongqing 已提交
132 133 134 135 136 137 138 139
  .then((data) => {
      console.log('Operation successful.')
  }).catch((error) => {
      console.log('Operation failed.');
  })
  ```


W
wusongqing 已提交
140
## AbilityContext.startAbilityForResult
W
wusongqing 已提交
141 142 143

startAbilityForResult(want: Want, callback: AsyncCallback&lt;AbilityResult&gt;): void;

W
wusongqing 已提交
144
Starts an ability. This API uses a callback to return the execution result when the ability is terminated.
W
wusongqing 已提交
145

W
wusongqing 已提交
146
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
W
wusongqing 已提交
147

W
wusongqing 已提交
148
**Parameters**
W
wusongqing 已提交
149

150
  | Name | Type | Mandatory | Description |
W
wusongqing 已提交
151
  | -------- | -------- | -------- | -------- |
W
wusongqing 已提交
152
  | want |[Want](js-apis-application-Want.md) | Yes| Information about the **Want** used for starting an ability.|
W
wusongqing 已提交
153
  | callback | AsyncCallback&lt;[AbilityResult](js-apis-featureAbility.md#abilityresult)&gt; | Yes| Callback used to return the result.|
W
wusongqing 已提交
154 155


W
wusongqing 已提交
156 157 158
**Example**

  ```js
W
wusongqing 已提交
159 160 161 162 163 164 165 166 167
  this.context.startAbilityForResult(
      {bundleName: "com.extreme.myapplication", abilityName: "MainAbilityDemo2"},
      (error, result) => {
          console.log("startAbilityForResult AsyncCallback is called, error.code = " + error.code)
          console.log("startAbilityForResult AsyncCallback is called, result.resultCode = " + result.resultCode)
       }
  );
  ```

W
wusongqing 已提交
168
## AbilityContext.startAbilityForResult
W
wusongqing 已提交
169 170 171

startAbilityForResult(want: Want, options: StartOptions, callback: AsyncCallback&lt;AbilityResult&gt;): void;

W
wusongqing 已提交
172
Starts an ability. This API uses a callback to return the execution result when the ability is terminated.
W
wusongqing 已提交
173

W
wusongqing 已提交
174
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
W
wusongqing 已提交
175

W
wusongqing 已提交
176
**Parameters**
W
wusongqing 已提交
177

178
  | Name | Type | Mandatory | Description |
W
wusongqing 已提交
179
  | -------- | -------- | -------- | -------- |
W
wusongqing 已提交
180
  | want |[Want](js-apis-application-Want.md) | Yes| Information about the **Want** used for starting an ability.|
W
wusongqing 已提交
181 182 183 184
  | options | StartOptions | Yes| Parameters used for starting the ability.|
  | callback | AsyncCallback&lt;[AbilityResult](js-apis-featureAbility.md#abilityresult)&gt; | Yes| Callback used to return the result.|


W
wusongqing 已提交
185 186 187
**Example**

  ```js
W
wusongqing 已提交
188 189 190 191 192 193 194 195 196 197 198 199
  var options = {
    windowMode: 0,
  };
  this.context.startAbilityForResult(
      {bundleName: "com.extreme.myapplication", abilityName: "MainAbilityDemo2"}, options,
      (error, result) => {
          console.log("startAbilityForResult AsyncCallback is called, error.code = " + error.code)
          console.log("startAbilityForResult AsyncCallback is called, result.resultCode = " + result.resultCode)
       }
  );
  ```

W
wusongqing 已提交
200

W
wusongqing 已提交
201
## AbilityContext.startAbilityForResult
W
wusongqing 已提交
202

W
wusongqing 已提交
203
startAbilityForResult(want: Want, options?: StartOptions): Promise&lt;AbilityResult&gt;;
W
wusongqing 已提交
204

W
wusongqing 已提交
205
Starts an ability. This API uses a promise to return the execution result when the ability is terminated.
W
wusongqing 已提交
206

W
wusongqing 已提交
207
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
W
wusongqing 已提交
208

W
wusongqing 已提交
209
**Parameters**
W
wusongqing 已提交
210

211
  | Name | Type | Mandatory | Description | 
W
wusongqing 已提交
212
  | -------- | -------- | -------- | -------- |
W
wusongqing 已提交
213
  | want | [Want](js-apis-application-Want.md) | Yes| Information about the **Want** used for starting an ability.|
W
wusongqing 已提交
214
  | options | StartOptions | No| Parameters used for starting the ability.|
W
wusongqing 已提交
215

W
wusongqing 已提交
216

W
wusongqing 已提交
217 218
**Return value**

219
  | Type | Description |
W
wusongqing 已提交
220
  | -------- | -------- |
W
wusongqing 已提交
221
  | Promise&lt;[AbilityResult](js-apis-featureAbility.md#abilityresult)&gt; | Promise used to return the result.|
W
wusongqing 已提交
222

W
wusongqing 已提交
223 224 225
**Example**

  ```js
W
wusongqing 已提交
226 227 228 229
  var options = {
    windowMode: 0,
  };
  this.context.startAbilityForResult({bundleName: "com.extreme.myapplication", abilityName: "MainAbilityDemo2"}, options).then((result) => {
W
wusongqing 已提交
230 231 232 233 234 235 236
      console.log("startAbilityForResult Promise.resolve is called, result.resultCode = " + result.resultCode)
  }, (error) => {
      console.log("startAbilityForResult Promise.Reject is called, error.code = " + error.code)
  })
  ```


W
wusongqing 已提交
237
## AbilityContext.terminateSelf
W
wusongqing 已提交
238 239 240

terminateSelf(callback: AsyncCallback&lt;void&gt;): void;

W
wusongqing 已提交
241
Terminates this ability. This API uses a callback to return the result.
W
wusongqing 已提交
242

W
wusongqing 已提交
243
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
W
wusongqing 已提交
244

W
wusongqing 已提交
245
**Parameters**
W
wusongqing 已提交
246

247
  | Name | Type | Mandatory | Description | 
W
wusongqing 已提交
248
  | -------- | -------- | -------- | -------- |
W
wusongqing 已提交
249
  | callback | AsyncCallback&lt;void&gt; | Yes| Callback used to return the result indicating whether the API is successfully called.| 
W
wusongqing 已提交
250

W
wusongqing 已提交
251 252 253
**Example**

  ```js
W
wusongqing 已提交
254
  this.context.terminateSelf((err) => {
W
wusongqing 已提交
255
      console.log('terminateSelf result:' + JSON.stringify(err));
W
wusongqing 已提交
256
  });
W
wusongqing 已提交
257 258 259
  ```


W
wusongqing 已提交
260
## AbilityContext.terminateSelf
W
wusongqing 已提交
261 262 263

terminateSelf(): Promise&lt;void&gt;;

W
wusongqing 已提交
264
Terminates this ability. This API uses a promise to return the result.
W
wusongqing 已提交
265

W
wusongqing 已提交
266
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
W
wusongqing 已提交
267

W
wusongqing 已提交
268
**Return value**
W
wusongqing 已提交
269

270
  | Type | Description | 
W
wusongqing 已提交
271
  | -------- | -------- |
W
wusongqing 已提交
272
  | Promise&lt;void&gt; | Promise used to return the result indicating whether the API is successfully called.| 
W
wusongqing 已提交
273

W
wusongqing 已提交
274 275 276
**Example**

  ```js
W
wusongqing 已提交
277
  this.context.terminateSelf(want).then((data) => {
W
wusongqing 已提交
278
      console.log('success:' + JSON.stringify(data));
W
wusongqing 已提交
279
  }).catch((error) => {
W
wusongqing 已提交
280
      console.log('failed:' + JSON.stringify(error));
W
wusongqing 已提交
281 282 283 284
  });
  ```


W
wusongqing 已提交
285
## AbilityContext.terminateSelfWithResult
W
wusongqing 已提交
286 287 288

terminateSelfWithResult(parameter: AbilityResult, callback: AsyncCallback&lt;void&gt;): void;

W
wusongqing 已提交
289
Terminates this ability. This API uses a callback to return the information to the caller of **startAbilityForResult**.
W
wusongqing 已提交
290

W
wusongqing 已提交
291
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
W
wusongqing 已提交
292

W
wusongqing 已提交
293
**Parameters**
W
wusongqing 已提交
294

295
  | Name | Type | Mandatory | Description |
W
wusongqing 已提交
296
  | -------- | -------- | -------- | -------- |
W
wusongqing 已提交
297
  | parameter | [AbilityResult](js-apis-featureAbility.md#abilityresult) | Yes| Information returned to the caller.|
W
wusongqing 已提交
298
  | callback | AsyncCallback&lt;void&gt; | Yes| Callback used to return the result.|
W
wusongqing 已提交
299

W
wusongqing 已提交
300 301 302
**Example**

  ```js
W
wusongqing 已提交
303 304 305 306 307 308 309 310 311 312 313
  this.context.terminateSelfWithResult(
     {
          want: {bundleName: "com.extreme.myapplication", abilityName: "MainAbilityDemo"},
          resultCode: 100
      }, (error) => {
          console.log("terminateSelfWithResult is called = " + error.code)
      }
  );
  ```


W
wusongqing 已提交
314
## AbilityContext.terminateSelfWithResult
W
wusongqing 已提交
315 316 317

terminateSelfWithResult(parameter: AbilityResult): Promise&lt;void&gt;;

W
wusongqing 已提交
318
Terminates this ability. This API uses a promise to return information to the caller of **startAbilityForResult**.
W
wusongqing 已提交
319

W
wusongqing 已提交
320
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
W
wusongqing 已提交
321

W
wusongqing 已提交
322
**Parameters**
W
wusongqing 已提交
323

324
  | Name | Type | Mandatory | Description |
W
wusongqing 已提交
325
  | -------- | -------- | -------- | -------- |
W
wusongqing 已提交
326
  | parameter | [AbilityResult](js-apis-featureAbility.md#abilityresult) | Yes| Information returned to the caller.|
W
wusongqing 已提交
327

W
wusongqing 已提交
328 329
**Return value**

330
  | Type | Description | 
W
wusongqing 已提交
331
  | -------- | -------- |
W
wusongqing 已提交
332
  | Promise&lt;void&gt; | Promise used to return the result.| 
W
wusongqing 已提交
333

W
wusongqing 已提交
334 335 336
**Example**

  ```js
W
wusongqing 已提交
337 338 339 340 341 342 343 344 345
  this.context.terminateSelfWithResult(
  {
      want: {bundleName: "com.extreme.myapplication", abilityName: "MainAbilityDemo"},
      resultCode: 100
  }).then((result) => {
      console.log("terminateSelfWithResult")
  }
  )
  ```
W
wusongqing 已提交
346 347


W
wusongqing 已提交
348
## AbilityContext.startAbilityByCall
W
wusongqing 已提交
349 350 351 352 353

startAbilityByCall(want: Want): Promise&lt;Caller&gt;;

Obtains the caller interface of the specified ability, and if the specified ability is not started, starts the ability in the background.

W
wusongqing 已提交
354
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
W
wusongqing 已提交
355

W
wusongqing 已提交
356
**Parameters**
W
wusongqing 已提交
357

358
  | Name | Type | Mandatory | Description | 
W
wusongqing 已提交
359
  | -------- | -------- | -------- | -------- |
W
wusongqing 已提交
360
  | want | [Want](js-apis-application-Want.md) | Yes| Information about the ability to start, including the ability name, bundle name, and device ID. If the device ID is left blank or the default value is used, the local ability will be started.| 
W
wusongqing 已提交
361

W
wusongqing 已提交
362 363
**Return value**

364
  | Type | Description | 
W
wusongqing 已提交
365
  | -------- | -------- |
W
wusongqing 已提交
366
  | Promise&lt;Caller&gt; | Promise used to return the caller object to communicate with.| 
W
wusongqing 已提交
367

W
wusongqing 已提交
368
**Example**
W
wusongqing 已提交
369
    
W
wusongqing 已提交
370
  ```js
W
wusongqing 已提交
371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389
  import Ability from '@ohos.application.Ability';
  var caller;
  export default class MainAbility extends Ability {
      onWindowStageCreate(windowStage) {
          this.context.startAbilityByCall({
              bundleName: "com.example.myservice",
              abilityName: "com.example.myservice.MainAbility",
              deviceId: ""
          }).then((obj) => {
              caller = obj;
              console.log('Caller GetCaller Get ' + call);
          }).catch((e) => {
              console.log('Caller GetCaller error ' + e);
          });
      }
  }
  ```


W
wusongqing 已提交
390
## AbilityContext.requestPermissionsFromUser
W
wusongqing 已提交
391 392 393

requestPermissionsFromUser(permissions: Array&lt;string&gt;, requestCallback: AsyncCallback&lt;PermissionRequestResult&gt;) : void;

W
wusongqing 已提交
394
Requests permissions from the user by displaying a pop-up window. This API uses a callback to return the result.
W
wusongqing 已提交
395

W
wusongqing 已提交
396
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
W
wusongqing 已提交
397

W
wusongqing 已提交
398
**Parameters**
W
wusongqing 已提交
399

400
  | Name | Type | Mandatory | Description | 
W
wusongqing 已提交
401 402
  | -------- | -------- | -------- | -------- |
  | permissions | Array&lt;string&gt; | Yes| Permissions to request.| 
W
wusongqing 已提交
403
  | callback | AsyncCallback&lt;[PermissionRequestResult](js-apis-permissionrequestresult.md)&gt; | Yes| Callback used to return the result indicating whether the API is successfully called.| 
W
wusongqing 已提交
404

W
wusongqing 已提交
405
**Example**
W
wusongqing 已提交
406 407 408
    
  ```
  this.context.requestPermissionsFromUser(permissions,(result) => {
W
wusongqing 已提交
409
      console.log('requestPermissionsFromUserresult:' + JSON.stringify(result));
W
wusongqing 已提交
410 411 412 413
  });
  ```


W
wusongqing 已提交
414
## AbilityContext.requestPermissionsFromUser
W
wusongqing 已提交
415 416 417

requestPermissionsFromUser(permissions: Array&lt;string&gt;) : Promise&lt;PermissionRequestResult&gt;;

W
wusongqing 已提交
418
Requests permissions from the user by displaying a pop-up window. This API uses a promise to return the result.
W
wusongqing 已提交
419

W
wusongqing 已提交
420
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
W
wusongqing 已提交
421

W
wusongqing 已提交
422
**Parameters**
W
wusongqing 已提交
423

424
  | Name | Type | Mandatory | Description | 
W
wusongqing 已提交
425
  | -------- | -------- | -------- | -------- |
W
wusongqing 已提交
426 427 428
  | permissions | Array&lt;string&gt; | Yes| Permissions to request.|

**Return value**
W
wusongqing 已提交
429

430
  | Type | Description | 
W
wusongqing 已提交
431
  | -------- | -------- |
W
wusongqing 已提交
432
  | Promise&lt;[PermissionRequestResult](js-apis-permissionrequestresult.md)&gt; | Promise used to return the result indicating whether the API is successfully called.| 
W
wusongqing 已提交
433

W
wusongqing 已提交
434
**Example**
W
wusongqing 已提交
435 436 437
    
  ```
  this.context.requestPermissionsFromUser(permissions).then((data) => {
W
wusongqing 已提交
438
      console.log('success:' + JSON.stringify(data));
W
wusongqing 已提交
439
  }).catch((error) => {
W
wusongqing 已提交
440
      console.log('failed:' + JSON.stringify(error));
W
wusongqing 已提交
441 442 443 444
  });
  ```


W
wusongqing 已提交
445
## AbilityContext.setMissionLabel
W
wusongqing 已提交
446 447 448

setMissionLabel(label: string, callback:AsyncCallback&lt;void&gt;): void;

W
wusongqing 已提交
449
Sets the label of the ability displayed in the task. This API uses a callback to return the result.
W
wusongqing 已提交
450

W
wusongqing 已提交
451
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
W
wusongqing 已提交
452

W
wusongqing 已提交
453
**Parameters**
W
wusongqing 已提交
454

455
  | Name | Type | Mandatory | Description | 
W
wusongqing 已提交
456 457
  | -------- | -------- | -------- | -------- |
  | label | string | Yes| Label of the ability to set.| 
W
wusongqing 已提交
458
  | callback | AsyncCallback&lt;void&gt; | Yes| Callback used to return the result indicating whether the API is successfully called.| 
W
wusongqing 已提交
459

W
wusongqing 已提交
460
**Example**
W
wusongqing 已提交
461
    
W
wusongqing 已提交
462
  ```js
W
wusongqing 已提交
463
  this.context.setMissionLabel("test",(result) => {
W
wusongqing 已提交
464
      console.log('requestPermissionsFromUserresult:' + JSON.stringify(result));
W
wusongqing 已提交
465 466 467 468
  });
  ```


W
wusongqing 已提交
469
## AbilityContext.setMissionLabel
W
wusongqing 已提交
470 471 472

setMissionLabel(label: string): Promise&lt;void&gt;

W
wusongqing 已提交
473
Sets the label of the ability displayed in the task. This API uses a promise to return the result.
W
wusongqing 已提交
474

W
wusongqing 已提交
475
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
W
wusongqing 已提交
476

W
wusongqing 已提交
477
**Parameters**
W
wusongqing 已提交
478

479
  | Name | Type | Mandatory | Description | 
W
wusongqing 已提交
480 481 482
  | -------- | -------- | -------- | -------- |
  | label | string | Yes| Label of the ability to set.| 

W
wusongqing 已提交
483 484
**Return value**

485
  | Type | Description | 
W
wusongqing 已提交
486
  | -------- | -------- |
W
wusongqing 已提交
487
  | Promise&lt;void&gt; | Promise used to return the result indicating whether the API is successfully called.| 
W
wusongqing 已提交
488

W
wusongqing 已提交
489
**Example**
W
wusongqing 已提交
490
    
W
wusongqing 已提交
491
  ```js
W
wusongqing 已提交
492
  this.context.setMissionLabel("test").then((data) => {
W
wusongqing 已提交
493
      console.log('success:' + JSON.stringify(data));
W
wusongqing 已提交
494
  }).catch((error) => {
W
wusongqing 已提交
495
      console.log('failed:' + JSON.stringify(error));
W
wusongqing 已提交
496 497
  });
  ```