1# @ohos.distributedDeviceManager (设备管理) 2 3本模块提供分布式设备管理能力。 4 5应用可调用接口实现如下功能: 6 7- 注册和解除注册设备上下线变化监听。 8- 发现周边不可信设备。 9- 认证和取消认证设备。 10- 查询可信设备列表。 11- 查询本地设备信息,包括设备名称,设备类型和设备标识等。 12 13> **说明:** 14> 15> 本模块首批接口从API version 10开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 16 17## 导入模块 18 19```ts 20import { distributedDeviceManager } from '@kit.DistributedServiceKit'; 21``` 22 23## distributedDeviceManager.createDeviceManager 24 25createDeviceManager(bundleName: string): DeviceManager 26 27创建一个设备管理实例。设备管理实例是分布式设备管理方法的调用入口。用于获取可信设备和本地设备的相关信息。 28 29**系统能力**:SystemCapability.DistributedHardware.DeviceManager 30 31**参数:** 32 33| 参数名 | 类型 | 必填 | 说明 | 34| ---------- | ---------------------------------------------------- | ---- | ----------------------------------------------------------- | 35| bundleName | string | 是 | 指示应用程序的Bundle名称。长度范围1~255字符。 | 36 37**返回值:** 38 39 | 类型 | 说明 | 40 | ------------------------------------------- | --------- | 41 | [DeviceManager](#devicemanager) | 返回设备管理器对象实例。 | 42 43**错误码:** 44 45以下的错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。 46 47| 错误码ID | 错误信息 | 48| -------- | --------------------------------------------------------------- | 49| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter type; 3. Parameter verification failed. | 50 51**示例:** 52 53 ```ts 54 import { distributedDeviceManager } from '@kit.DistributedServiceKit'; 55 import { BusinessError } from '@kit.BasicServicesKit'; 56 57 try { 58 let dmInstance = distributedDeviceManager.createDeviceManager('ohos.samples.jsHelloWorld'); 59 } catch(err) { 60 let e: BusinessError = err as BusinessError; 61 console.error('createDeviceManager errCode:' + e.code + ',errMessage:' + e.message); 62 } 63 ``` 64 65## distributedDeviceManager.releaseDeviceManager 66 67releaseDeviceManager(deviceManager: DeviceManager): void 68 69设备管理实例不再使用后,通过该方法释放DeviceManager实例。 70 71**系统能力**:SystemCapability.DistributedHardware.DeviceManager 72 73**参数:** 74 75| 参数名 | 类型 | 必填 | 说明 | 76| ---------- | ---------------------------------------------------- | ---- | --------------------------------- | 77| deviceManager | [DeviceManager](#devicemanager) | 是 | 设备管理器对象实例。 | 78 79**错误码:** 80 81以下的错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[设备管理错误码](errorcode-device-manager.md)。 82 83| 错误码ID | 错误信息 | 84| -------- | --------------------------------------------------------------- | 85| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 86| 11600101 | Failed to execute the function. | 87 88**示例:** 89 90 ```ts 91 import { distributedDeviceManager } from '@kit.DistributedServiceKit'; 92 import { BusinessError } from '@kit.BasicServicesKit'; 93 94 try { 95 let dmInstance = distributedDeviceManager.createDeviceManager('ohos.samples.jsHelloWorld'); 96 distributedDeviceManager.releaseDeviceManager(dmInstance); 97 } catch (err) { 98 let e: BusinessError = err as BusinessError; 99 console.error('release device manager errCode:' + e.code + ',errMessage:' + e.message); 100 } 101 ``` 102 103## DeviceBasicInfo 104 105分布式设备基本信息。 106 107**系统能力**:以下各项对应的系统能力均为SystemCapability.DistributedHardware.DeviceManager 108 109| 名称 | 类型 | 必填 | 说明 | 110| ---------------------- | ------------------------- | ---- | -------- | 111| deviceId | string | 是 | 设备标识符。实际值为udid-hash与appid和盐值基于sha256方式进行混淆后的值。| 112| deviceName | string | 是 | 设备名称。 | 113| deviceType | string | 是 | [设备类型](#getdevicetype)。 | 114| networkId | string | 否 | 设备网络标识。 | 115 116## DeviceStateChange 117 118表示设备状态。 119 120**系统能力**:以下各项对应的系统能力均为SystemCapability.DistributedHardware.DeviceManager 121 122| 名称 | 值 | 说明 | 123| ----------- | ---- | --------------- | 124| UNKNOWN | 0 | 设备物理上线,此时状态未知,在状态更改为可用之前,分布式业务无法使用。 | 125| AVAILABLE | 1 | 设备可用状态,表示设备间信息已在分布式数据中同步完成,可以运行分布式业务。 | 126| UNAVAILABLE | 2 | 设备物理下线,此时状态未知。 | 127 128## DeviceManager 129 130设备管理实例,用于获取可信设备和本地设备的相关信息。在调用DeviceManager的方法前,需要先通过createDeviceManager构建一个DeviceManager实例dmInstance。 131 132### getAvailableDeviceListSync 133 134getAvailableDeviceListSync(): Array<DeviceBasicInfo> 135 136同步获取所有可信设备列表。 137 138**需要权限**:ohos.permission.DISTRIBUTED_DATASYNC 139 140**系统能力**:SystemCapability.DistributedHardware.DeviceManager 141 142**返回值:** 143 144 | 类型 | 说明 | 145 | ------------------------------------------- | --------- | 146 | Array<[DeviceBasicInfo](#devicebasicinfo)> | 返回可信设备列表。 | 147 148**错误码:** 149 150以下的错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[设备管理错误码](errorcode-device-manager.md)。 151 152| 错误码ID | 错误信息 | 153| -------- | --------------------------------------------------------------- | 154| 201 | Permission verification failed. The application does not have the permission required to call the API. | 155| 11600101 | Failed to execute the function. | 156 157**示例:** 158 159 ```ts 160 import { distributedDeviceManager } from '@kit.DistributedServiceKit'; 161 import { BusinessError } from '@kit.BasicServicesKit'; 162 163 try { 164 let dmInstance = distributedDeviceManager.createDeviceManager('ohos.samples.jsHelloWorld'); 165 let deviceInfoList: Array<distributedDeviceManager.DeviceBasicInfo> = dmInstance.getAvailableDeviceListSync(); 166 } catch (err) { 167 let e: BusinessError = err as BusinessError; 168 console.error('getAvailableDeviceListSync errCode:' + e.code + ',errMessage:' + e.message); 169 } 170 ``` 171 172### getAvailableDeviceList 173 174getAvailableDeviceList(callback:AsyncCallback<Array<DeviceBasicInfo>>): void 175 176获取所有可信设备列表。使用callback异步回调。 177 178**需要权限**:ohos.permission.DISTRIBUTED_DATASYNC 179 180**系统能力**:SystemCapability.DistributedHardware.DeviceManager 181 182**参数:** 183 184 | 参数名 | 类型 | 必填 | 说明 | 185 | -------- | ---------------------------------------- | ---- | --------------------- | 186 | callback | AsyncCallback<Array<[DeviceBasicInfo](#devicebasicinfo)>> | 是 | 获取所有可信设备列表的回调,返回设备信息。 | 187 188**错误码:** 189 190以下的错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[设备管理错误码](errorcode-device-manager.md)。 191 192| 错误码ID | 错误信息 | 193| -------- | --------------------------------------------------------------- | 194| 201 | Permission verification failed. The application does not have the permission required to call the API. | 195| 11600101 | Failed to execute the function. | 196 197**示例:** 198 199 ```ts 200 import { distributedDeviceManager } from '@kit.DistributedServiceKit'; 201 import { BusinessError } from '@kit.BasicServicesKit'; 202 203 try { 204 let dmInstance = distributedDeviceManager.createDeviceManager('ohos.samples.jsHelloWorld'); 205 dmInstance.getAvailableDeviceList((err: BusinessError, data: Array<distributedDeviceManager.DeviceBasicInfo>) => { 206 if (err) { 207 console.error('getAvailableDeviceList errCode:' + err.code + ',errMessage:' + err.message); 208 return; 209 } 210 console.log('get available device info: ' + JSON.stringify(data)); 211 }); 212 } catch (err) { 213 let e: BusinessError = err as BusinessError; 214 console.error('getAvailableDeviceList errCode:' + e.code + ',errMessage:' + e.message); 215 } 216 ``` 217 218### getAvailableDeviceList 219 220getAvailableDeviceList(): Promise<Array<DeviceBasicInfo>> 221 222获取所有可信设备列表。使用Promise异步回调。 223 224**需要权限**:ohos.permission.DISTRIBUTED_DATASYNC 225 226**系统能力**:SystemCapability.DistributedHardware.DeviceManager 227 228**返回值:** 229 230 | 类型 | 说明 | 231 | ---------------------------------------------------------- | ---------------------------------- | 232 | Promise<Array<[DeviceBasicInfo](#devicebasicinfo)>> | Promise实例,用于获取异步返回结果。 | 233 234**错误码:** 235 236以下的错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[设备管理错误码](errorcode-device-manager.md)。 237 238| 错误码ID | 错误信息 | 239| -------- | --------------------------------------------------------------- | 240| 201 | Permission verification failed. The application does not have the permission required to call the API. | 241| 11600101 | Failed to execute the function. | 242 243**示例:** 244 245 ```ts 246 import { distributedDeviceManager } from '@kit.DistributedServiceKit'; 247 import { BusinessError } from '@kit.BasicServicesKit'; 248 let dmInstance = distributedDeviceManager.createDeviceManager('ohos.samples.jsHelloWorld'); 249 dmInstance.getAvailableDeviceList().then((data: Array<distributedDeviceManager.DeviceBasicInfo>) => { 250 console.log('get available device info: ' + JSON.stringify(data)); 251 }).catch((err: BusinessError) => { 252 console.error('getAvailableDeviceList errCode:' + err.code + ',errMessage:' + err.message); 253 }); 254 ``` 255 256### getLocalDeviceNetworkId 257 258getLocalDeviceNetworkId(): string 259 260获取本地设备网络标识。 261 262**需要权限**:ohos.permission.DISTRIBUTED_DATASYNC 263 264**系统能力**:SystemCapability.DistributedHardware.DeviceManager 265 266**返回值:** 267 268 | 类型 | 说明 | 269 | ------------------------- | ---------------- | 270 | string | 返回本地设备网络标识。 | 271 272**错误码:** 273 274以下的错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[设备管理错误码](errorcode-device-manager.md)。 275 276| 错误码ID | 错误信息 | 277| -------- | --------------------------------------------------------------- | 278| 201 | Permission verification failed. The application does not have the permission required to call the API. | 279| 11600101 | Failed to execute the function. | 280 281**示例:** 282 283 ```ts 284 import { distributedDeviceManager } from '@kit.DistributedServiceKit'; 285 import { BusinessError } from '@kit.BasicServicesKit'; 286 287 try { 288 let dmInstance = distributedDeviceManager.createDeviceManager('ohos.samples.jsHelloWorld'); 289 let deviceNetworkId: string = dmInstance.getLocalDeviceNetworkId(); 290 console.log('local device networkId: ' + JSON.stringify(deviceNetworkId)); 291 } catch (err) { 292 let e: BusinessError = err as BusinessError; 293 console.error('getLocalDeviceNetworkId errCode:' + e.code + ',errMessage:' + e.message); 294 } 295 ``` 296 297### getLocalDeviceName 298 299getLocalDeviceName(): string 300 301获取本地设备名称。 302 303**需要权限**:ohos.permission.DISTRIBUTED_DATASYNC 304 305**系统能力**:SystemCapability.DistributedHardware.DeviceManager 306 307**返回值:** 308 309 | 类型 | 说明 | 310 | ------------------------- | ---------------- | 311 | string | 返回本地设备名称。 | 312 313**错误码:** 314 315以下的错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[设备管理错误码](errorcode-device-manager.md)。 316 317| 错误码ID | 错误信息 | 318| -------- | --------------------------------------------------------------- | 319| 201 | Permission verification failed. The application does not have the permission required to call the API. | 320| 11600101 | Failed to execute the function. | 321 322**示例:** 323 324 ```ts 325 import { distributedDeviceManager } from '@kit.DistributedServiceKit'; 326 import { BusinessError } from '@kit.BasicServicesKit'; 327 328 try { 329 let dmInstance = distributedDeviceManager.createDeviceManager('ohos.samples.jsHelloWorld'); 330 let deviceName: string = dmInstance.getLocalDeviceName(); 331 console.log('local device name: ' + JSON.stringify(deviceName)); 332 } catch (err) { 333 let e: BusinessError = err as BusinessError; 334 console.error('getLocalDeviceName errCode:' + e.code + ',errMessage:' + e.message); 335 } 336 ``` 337 338### getLocalDeviceType 339 340getLocalDeviceType(): number 341 342获取本地设备类型。 343 344**需要权限**:ohos.permission.DISTRIBUTED_DATASYNC 345 346**系统能力**:SystemCapability.DistributedHardware.DeviceManager 347 348**返回值:** 349 350 | 类型 | 说明 | 351 | ------------------------- | ---------------- | 352 | number | <!--RP1-->返回本地设备类型。<!--RP1End--> | 353 354**错误码:** 355 356以下的错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[设备管理错误码](errorcode-device-manager.md)。 357 358| 错误码ID | 错误信息 | 359| -------- | --------------------------------------------------------------- | 360| 201 | Permission verification failed. The application does not have the permission required to call the API. | 361| 11600101 | Failed to execute the function. | 362 363**示例:** 364 365 ```ts 366 import { distributedDeviceManager } from '@kit.DistributedServiceKit'; 367 import { BusinessError } from '@kit.BasicServicesKit'; 368 369 try { 370 let dmInstance = distributedDeviceManager.createDeviceManager('ohos.samples.jsHelloWorld'); 371 let deviceType: number = dmInstance.getLocalDeviceType(); 372 console.log('local device type: ' + JSON.stringify(deviceType)); 373 } catch (err) { 374 let e: BusinessError = err as BusinessError; 375 console.error('getLocalDeviceType errCode:' + e.code + ',errMessage:' + e.message); 376 } 377 ``` 378 379### getLocalDeviceId 380 381getLocalDeviceId(): string 382 383获取本地设备id,实际值为udid-hash与appid和盐值基于sha256方式进行混淆后的值。 384 385**需要权限**:ohos.permission.DISTRIBUTED_DATASYNC 386 387**系统能力**:SystemCapability.DistributedHardware.DeviceManager 388 389**返回值:** 390 391 | 类型 | 说明 | 392 | ------------------------- | ---------------- | 393 | string | 返回本地设备id。 | 394 395**错误码:** 396 397以下的错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[设备管理错误码](errorcode-device-manager.md)。 398 399| 错误码ID | 错误信息 | 400| -------- | --------------------------------------------------------------- | 401| 201 | Permission verification failed. The application does not have the permission required to call the API. | 402| 11600101 | Failed to execute the function. | 403 404**示例:** 405 406 ```ts 407 import { distributedDeviceManager } from '@kit.DistributedServiceKit'; 408 import { BusinessError } from '@kit.BasicServicesKit'; 409 410 try { 411 let dmInstance = distributedDeviceManager.createDeviceManager('ohos.samples.jsHelloWorld'); 412 let deviceId: string = dmInstance.getLocalDeviceId(); 413 console.log('local device id: ' + JSON.stringify(deviceId)); 414 } catch (err) { 415 let e: BusinessError = err as BusinessError; 416 console.error('getLocalDeviceId errCode:' + e.code + ',errMessage:' + e.message); 417 } 418 ``` 419 420### getDeviceName 421 422getDeviceName(networkId: string): string 423 424通过指定设备的网络标识获取该设备名称。 425 426**需要权限**:ohos.permission.DISTRIBUTED_DATASYNC 427 428**系统能力**:SystemCapability.DistributedHardware.DeviceManager 429 430**参数:** 431 432 | 参数名 | 类型 | 必填 | 说明 | 433 | -------- | ---------------------------------------- | ---- | --------- | 434 | networkId| string | 是 | 设备的网络标识。长度范围1~255字符。 | 435 436**返回值:** 437 438 | 类型 | 说明 | 439 | ------------------------- | ---------------- | 440 | string | 返回指定设备名称。 | 441 442**错误码:** 443 444以下的错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[设备管理错误码](errorcode-device-manager.md)。 445 446| 错误码ID | 错误信息 | 447| -------- | --------------------------------------------------------------- | 448| 201 | Permission verification failed. The application does not have the permission required to call the API. | 449| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter type; 3. Parameter verification failed; 4. The size of specified networkId is greater than 255. | 450| 11600101 | Failed to execute the function. | 451 452**示例:** 453 454 ```ts 455 import { distributedDeviceManager } from '@kit.DistributedServiceKit'; 456 import { BusinessError } from '@kit.BasicServicesKit'; 457 458 try { 459 // 设备网络标识,可以从可信设备列表中获取 460 let networkId = 'xxxxxxx'; 461 let dmInstance = distributedDeviceManager.createDeviceManager('ohos.samples.jsHelloWorld'); 462 let deviceName: string = dmInstance.getDeviceName(networkId); 463 console.log('device name: ' + JSON.stringify(deviceName)); 464 } catch (err) { 465 let e: BusinessError = err as BusinessError; 466 console.error('getDeviceName errCode:' + e.code + ',errMessage:' + e.message); 467 } 468 ``` 469 470### getDeviceType 471 472getDeviceType(networkId: string): number 473 474通过指定设备的网络标识获取该设备类型。 475 476**需要权限**:ohos.permission.DISTRIBUTED_DATASYNC 477 478**系统能力**:SystemCapability.DistributedHardware.DeviceManager 479 480**参数:** 481 482 | 参数名 | 类型 | 必填 | 说明 | 483 | -------- | ---------------------------------------- | ---- | --------- | 484 | networkId| string | 是 | 设备的网络标识。长度范围1~255字符。 | 485 486**返回值:** 487 488 | 类型 | 说明 | 489 | ------------------------- | ---------------- | 490 | number | <!--RP2-->返回指定设备类型。<!--RP2End--> | 491 492**错误码:** 493 494以下的错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[设备管理错误码](errorcode-device-manager.md)。 495 496| 错误码ID | 错误信息 | 497| -------- | --------------------------------------------------------------- | 498| 201 | Permission verification failed. The application does not have the permission required to call the API. | 499| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter type; 3. Parameter verification failed; 4. The size of specified networkId is greater than 255. | 500| 11600101 | Failed to execute the function. | 501 502**示例:** 503 504 ```ts 505 import { distributedDeviceManager } from '@kit.DistributedServiceKit'; 506 import { BusinessError } from '@kit.BasicServicesKit'; 507 508 try { 509 // 设备网络标识,可以从可信设备列表中获取 510 let networkId = 'xxxxxxx'; 511 let dmInstance = distributedDeviceManager.createDeviceManager('ohos.samples.jsHelloWorld'); 512 let deviceType: number = dmInstance.getDeviceType(networkId); 513 console.log('device type: ' + JSON.stringify(deviceType)); 514 } catch (err) { 515 let e: BusinessError = err as BusinessError; 516 console.error('getDeviceType errCode:' + e.code + ',errMessage:' + e.message); 517 } 518 ``` 519 520### startDiscovering 521 522startDiscovering(discoverParam: {[key: string]: Object;} , filterOptions?: {[key: string]: Object;} ): void 523 524发现周边设备。发现状态持续两分钟,超过两分钟,会停止发现,最大发现数量99个。wifi场景要求同局域网。 525 526**需要权限**:ohos.permission.DISTRIBUTED_DATASYNC 527 528**系统能力**:SystemCapability.DistributedHardware.DeviceManager 529 530**参数:** 531 532 | 参数名 | 类型 | 必填 | 说明 | 533 | ------------- | ------------------------------- | ---- | ----- | 534 | discoverParam | {[key: string]: Object;} | 是 | 发现标识。 标识发现的目标类型。<br>discoverTargetType: 发现目标默认为设备,值为1。| 535 | filterOptions | {[key: string]: Object;} | 否 | 发现设备过滤信息。可选,默认为undefined,发现未上线设备。会携带以下key值:<br>availableStatus(0-1):仅发现设备可信,值为0表示设备不可信。<br />-0:设备离线,客户端需要通过调用bindTarget绑定设备。<br />-1:设备已在线,客户可以进行连接。<br>discoverDistance(0-100):发现距离本地一定距离内的设备,单位为cm。wifi场景不传该参数。 <br>authenticationStatus(0-1):根据不同的认证状态发现设备:<br />-0:设备未认证。<br />-1:设备已认证。<br>authorizationType(0-2):根据不同的授权类型发现设备:<br />-0:根据临时协商的会话密钥认证的设备。<br />-1:基于同账号密钥进行身份验证的设备。<br />-2:基于不同账号凭据密钥认证的设备。| 536 537**错误码:** 538 539以下的错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[设备管理错误码](errorcode-device-manager.md)。 540 541| 错误码ID | 错误信息 | 542| -------- | --------------------------------------------------------------- | 543| 201 | Permission verification failed. The application does not have the permission required to call the API. | 544| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter type; 3. Parameter verification failed. | 545| 11600101 | Failed to execute the function. | 546| 11600104 | Discovery unavailable. | 547 548**示例:** 549 550 ```ts 551 import { distributedDeviceManager } from '@kit.DistributedServiceKit'; 552 import { BusinessError } from '@kit.BasicServicesKit'; 553 554 interface DiscoverParam { 555 discoverTargetType: number; 556 } 557 558 interface FilterOptions { 559 availableStatus: number; 560 discoverDistance: number; 561 authenticationStatus: number; 562 authorizationType: number; 563 } 564 565 let discoverParam: Record<string, number> = { 566 'discoverTargetType': 1 567 }; 568 let filterOptions: Record<string, number> = { 569 'availableStatus': 0 570 }; 571 572 try { 573 let dmInstance = distributedDeviceManager.createDeviceManager('ohos.samples.jsHelloWorld'); 574 dmInstance.startDiscovering(discoverParam, filterOptions); // 当有设备发现时,通过discoverSuccess回调通知给应用程序 575 } catch (err) { 576 let e: BusinessError = err as BusinessError; 577 console.error('startDiscovering errCode:' + e.code + ',errMessage:' + e.message); 578 } 579 ``` 580 581### stopDiscovering 582 583stopDiscovering(): void 584 585停止发现周边设备。 586 587**需要权限**:ohos.permission.DISTRIBUTED_DATASYNC 588 589**系统能力**:SystemCapability.DistributedHardware.DeviceManager 590 591**错误码:** 592 593以下的错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[设备管理错误码](errorcode-device-manager.md)。 594 595| 错误码ID | 错误信息 | 596| -------- | --------------------------------------------------------------- | 597| 201 | Permission verification failed. The application does not have the permission required to call the API. | 598| 11600101 | Failed to execute the function. | 599 600**示例:** 601 602 ```ts 603 import { distributedDeviceManager } from '@kit.DistributedServiceKit'; 604 import { BusinessError } from '@kit.BasicServicesKit'; 605 606 try { 607 let dmInstance = distributedDeviceManager.createDeviceManager('ohos.samples.jsHelloWorld'); 608 dmInstance.stopDiscovering(); 609 } catch (err) { 610 let e: BusinessError = err as BusinessError; 611 console.error('stopDiscovering errCode:' + e.code + ',errMessage:' + e.message); 612 } 613 ``` 614 615### bindTarget 616 617bindTarget(deviceId: string, bindParam: {[key: string]: Object;} , callback: AsyncCallback<{deviceId: string;}>): void 618 619认证设备。 620 621**需要权限**:ohos.permission.DISTRIBUTED_DATASYNC 622 623**系统能力**:SystemCapability.DistributedHardware.DeviceManager 624 625**参数:** 626 627 | 参数名 | 类型 | 必填 | 说明 | 628 | ---------- | --------------------------------------------------- | ----- | ------------ | 629 | deviceId | string | 是 | 设备标识。长度范围1~255字符。 | 630 | bindParam | {[key: string]: Object;} | 是 | 认证参数。由开发者自行决定传入的键值对。默认会携带以下key值:<br>bindType 此值是绑定的类型,必填。<br />-1:PIN码。<br>targetPkgName 绑定目标的包名。<br>appName 尝试绑定目标的应用程序名称。<br>appOperation 应用程序要绑定目标的原因。<br>customDescription 操作的详细说明。 | 631 | callback | AsyncCallback<{deviceId: string; }> | 是 | 认证结果回调。 | 632 633**错误码:** 634 635以下的错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[设备管理错误码](errorcode-device-manager.md)。 636 637| 错误码ID | 错误信息 | 638| -------- | --------------------------------------------------------------- | 639| 201 | Permission verification failed. The application does not have the permission required to call the API. | 640| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter type; 3. Parameter verification failed; 4. The size of specified deviceId is greater than 255. | 641| 11600101 | Failed to execute the function. | 642| 11600103 | Authentication unavailable. | 643 644**示例:** 645 646 ```ts 647 import { distributedDeviceManager } from '@kit.DistributedServiceKit'; 648 import { BusinessError } from '@kit.BasicServicesKit'; 649 650 class Data { 651 deviceId: string = ''; 652 } 653 654 // 认证的设备信息,可以从发现的结果中获取 655 let deviceId = 'XXXXXXXX'; 656 let bindParam: Record<string, string | number> = { 657 'bindType': 1, // 认证类型: 1 - 无账号PIN码认证 658 'targetPkgName': 'xxxx', 659 'appName': 'xxxx', 660 'appOperation': 'xxxx', 661 'customDescription': 'xxxx' 662 }; 663 664 try { 665 let dmInstance = distributedDeviceManager.createDeviceManager('ohos.samples.jsHelloWorld'); 666 dmInstance.bindTarget(deviceId, bindParam, (err: BusinessError, data: Data) => { 667 if (err) { 668 console.error('bindTarget errCode:' + err.code + ',errMessage:' + err.message); 669 return; 670 } 671 console.info('bindTarget result:' + JSON.stringify(data)); 672 }); 673 } catch (err) { 674 let e: BusinessError = err as BusinessError; 675 console.error('bindTarget errCode:' + e.code + ',errMessage:' + e.message); 676 } 677 ``` 678 679### unbindTarget 680 681unbindTarget(deviceId: string): void 682 683解除认证设备。 684 685**需要权限**:ohos.permission.DISTRIBUTED_DATASYNC 686 687**系统能力**:SystemCapability.DistributedHardware.DeviceManager 688 689**参数:** 690 691 | 参数名 | 类型 | 必填 | 说明 | 692 | -------- | ------------------------- | ---- | ---------- | 693 | deviceId | string | 是 | 设备标识。长度范围1~255字符。 | 694 695**错误码:** 696 697以下的错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[设备管理错误码](errorcode-device-manager.md)。 698 699| 错误码ID | 错误信息 | 700| -------- | --------------------------------------------------------------- | 701| 201 | Permission verification failed. The application does not have the permission required to call the API. | 702| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter type; 3. Parameter verification failed; 4. The size of specified deviceId is greater than 255. | 703| 11600101 | Failed to execute the function. | 704 705**示例:** 706 707 ```ts 708 import { distributedDeviceManager } from '@kit.DistributedServiceKit'; 709 import { BusinessError } from '@kit.BasicServicesKit'; 710 711 try { 712 let deviceId = 'XXXXXXXX'; 713 let dmInstance = distributedDeviceManager.createDeviceManager('ohos.samples.jsHelloWorld'); 714 dmInstance.unbindTarget(deviceId); 715 } catch (err) { 716 let e: BusinessError = err as BusinessError; 717 console.error('unbindTarget errCode:' + e.code + ',errMessage:' + e.message); 718 } 719 ``` 720 721### on('deviceStateChange') 722 723on(type: 'deviceStateChange', callback: Callback<{ action: DeviceStateChange; device: DeviceBasicInfo; }>): void 724 725注册设备状态回调,以便在设备状态发生变化时根据应用捆绑包名通知应用。 726 727**需要权限**:ohos.permission.DISTRIBUTED_DATASYNC 728 729**系统能力**:SystemCapability.DistributedHardware.DeviceManager 730 731**参数:** 732 733 | 参数名 | 类型 | 必填 | 说明 | 734 | -------- | ---------------------------------------- | ---- | ------------------------------ | 735 | type | string | 是 | 注册设备状态回调,固定为deviceStateChange。 | 736 | callback | Callback<{ action: [DeviceStateChange](#devicestatechange); device: [DeviceBasicInfo](#devicebasicinfo); }> | 是 | 指示要注册的设备状态回调,返回设备状态和设备信息。 | 737 738**错误码:** 739 740以下的错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。 741 742| 错误码ID | 错误信息 | 743| -------- | --------------------------------------------------------------- | 744| 201 | Permission verification failed. The application does not have the permission required to call the API. | 745| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter type; 3. Parameter verification failed; 4. The size of specified type is greater than 255. | 746 747**示例:** 748 749 ```ts 750 import { distributedDeviceManager } from '@kit.DistributedServiceKit'; 751 import { BusinessError } from '@kit.BasicServicesKit'; 752 753 class Data { 754 action: distributedDeviceManager.DeviceStateChange = 0; 755 device: distributedDeviceManager.DeviceBasicInfo = { 756 deviceId: '', 757 deviceName: '', 758 deviceType: '', 759 networkId: '' 760 }; 761 } 762 763 try { 764 let dmInstance = distributedDeviceManager.createDeviceManager('ohos.samples.jsHelloWorld'); 765 dmInstance.on('deviceStateChange', (data: Data) => { 766 console.info('deviceStateChange on:' + JSON.stringify(data)); 767 }); 768 } catch (err) { 769 let e: BusinessError = err as BusinessError; 770 console.error('deviceStateChange errCode:' + e.code + ',errMessage:' + e.message); 771 } 772 ``` 773 774### off('deviceStateChange') 775 776off(type: 'deviceStateChange', callback?: Callback<{ action: DeviceStateChange; device: DeviceBasicInfo; }>): void 777 778取消注册设备状态回调。 779 780**需要权限**:ohos.permission.DISTRIBUTED_DATASYNC 781 782**系统能力**:SystemCapability.DistributedHardware.DeviceManager 783 784**参数:** 785 786 | 参数名 | 类型 | 必填 | 说明 | 787 | -------- | ---------------------------------------- | ---- | --------------------------- | 788 | type | string | 是 | 根据应用程序的包名取消注册设备状态回调,固定为deviceStateChange。 | 789 | callback | Callback<{ action: [DeviceStateChange](#devicestatechange); device: [DeviceBasicInfo](#devicebasicinfo); }> | 否 | 指示要取消注册的设备状态回调,返回设备状态和设备信息。 | 790 791**错误码:** 792 793以下的错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。 794 795| 错误码ID | 错误信息 | 796| -------- | --------------------------------------------------------------- | 797| 201 | Permission verification failed. The application does not have the permission required to call the API. | 798| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter type; 3. Parameter verification failed; 4. The size of specified type is greater than 255. | 799 800**示例:** 801 802 ```ts 803 import { distributedDeviceManager } from '@kit.DistributedServiceKit'; 804 import { BusinessError } from '@kit.BasicServicesKit'; 805 806 class Data { 807 action: distributedDeviceManager.DeviceStateChange = 0; 808 device: distributedDeviceManager.DeviceBasicInfo = { 809 deviceId: '', 810 deviceName: '', 811 deviceType: '', 812 networkId: '' 813 }; 814 } 815 816 try { 817 let dmInstance = distributedDeviceManager.createDeviceManager('ohos.samples.jsHelloWorld'); 818 dmInstance.off('deviceStateChange', (data: Data) => { 819 console.info('deviceStateChange' + JSON.stringify(data)); 820 }); 821 } catch (err) { 822 let e: BusinessError = err as BusinessError; 823 console.error('deviceStateChange errCode:' + e.code + ',errMessage:' + e.message); 824 } 825 ``` 826 827### on('discoverSuccess') 828 829on(type: 'discoverSuccess', callback: Callback<{ device: DeviceBasicInfo; }>): void 830 831注册发现设备成功回调监听。 832 833**需要权限**:ohos.permission.DISTRIBUTED_DATASYNC 834 835**系统能力**:SystemCapability.DistributedHardware.DeviceManager 836 837**参数:** 838 839 | 参数名 | 类型 | 必填 | 说明 | 840 | -------- | ---------------------------------------- | ---- | -------------------------- | 841 | type | string | 是 | 注册设备发现回调,以便在发现周边设备时通知应用程序,固定为discoverSuccess。 | 842 | callback | Callback<{ device: [DeviceBasicInfo](#devicebasicinfo); }> | 是 | 注册设备发现的回调方法。 | 843 844**错误码:** 845 846以下的错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。 847 848| 错误码ID | 错误信息 | 849| -------- | --------------------------------------------------------------- | 850| 201 | Permission verification failed. The application does not have the permission required to call the API. | 851| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter type; 3. Parameter verification failed; 4. The size of specified type is greater than 255. | 852 853**示例:** 854 855 ```ts 856 import { distributedDeviceManager } from '@kit.DistributedServiceKit'; 857 import { BusinessError } from '@kit.BasicServicesKit'; 858 859 class Data { 860 device: distributedDeviceManager.DeviceBasicInfo = { 861 deviceId: '', 862 deviceName: '', 863 deviceType: '', 864 networkId: '' 865 }; 866 } 867 868 try { 869 let dmInstance = distributedDeviceManager.createDeviceManager('ohos.samples.jsHelloWorld'); 870 dmInstance.on('discoverSuccess', (data: Data) => { 871 console.info('discoverSuccess:' + JSON.stringify(data)); 872 }); 873 } catch (err) { 874 let e: BusinessError = err as BusinessError; 875 console.error('discoverSuccess errCode:' + e.code + ',errMessage:' + e.message); 876 } 877 ``` 878 879### off('discoverSuccess') 880 881off(type: 'discoverSuccess', callback?: Callback<{ device: DeviceBasicInfo; }>): void 882 883取消注册设备发现成功回调。 884 885**需要权限**:ohos.permission.DISTRIBUTED_DATASYNC 886 887**系统能力**:SystemCapability.DistributedHardware.DeviceManager 888 889**参数:** 890 891 | 参数名 | 类型 | 必填 | 说明 | 892 | -------- | ---------------------------------------- | ---- | --------------------------- | 893 | type | string | 是 | 取消注册设备发现回调,固定为discoverSuccess。 | 894 | callback | Callback<{ device: [DeviceBasicInfo](#devicebasicinfo); }> | 否 | 指示要取消注册的设备发现回调,返回设备状态和设备信息。 | 895 896**错误码:** 897 898以下的错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。 899 900| 错误码ID | 错误信息 | 901| -------- | --------------------------------------------------------------- | 902| 201 | Permission verification failed. The application does not have the permission required to call the API. | 903| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter type; 3. Parameter verification failed; 4. The size of specified type is greater than 255. | 904 905**示例:** 906 907 ```ts 908 import { distributedDeviceManager } from '@kit.DistributedServiceKit'; 909 import { BusinessError } from '@kit.BasicServicesKit'; 910 911 class Data { 912 device: distributedDeviceManager.DeviceBasicInfo = { 913 deviceId: '', 914 deviceName: '', 915 deviceType: '', 916 networkId: '' 917 }; 918 } 919 920 try { 921 let dmInstance = distributedDeviceManager.createDeviceManager('ohos.samples.jsHelloWorld'); 922 dmInstance.off('discoverSuccess', (data: Data) => { 923 console.info('discoverSuccess' + JSON.stringify(data)); 924 }); 925 } catch (err) { 926 let e: BusinessError = err as BusinessError; 927 console.error('discoverSuccess errCode:' + e.code + ',errMessage:' + e.message); 928 } 929 ``` 930 931### on('deviceNameChange') 932 933on(type: 'deviceNameChange', callback: Callback<{ deviceName: string; }>): void 934 935注册设备名称变更回调,以便在设备名称改变时通知应用程序。 936 937**需要权限**:ohos.permission.DISTRIBUTED_DATASYNC 938 939**系统能力**:SystemCapability.DistributedHardware.DeviceManager 940 941**参数:** 942 943 | 参数名 | 类型 | 必填 | 说明 | 944 | -------- | ---------------------------------------- | ---- | ------------------------------ | 945 | type | string | 是 | 注册设备名称改变回调,以便在设备名称改变时通知应用程序,固定为deviceNameChange。 | 946 | callback | Callback<{ deviceName: string;}> | 是 | 注册设备名称改变的回调方法。 | 947 948**错误码:** 949 950以下的错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。 951 952| 错误码ID | 错误信息 | 953| -------- | --------------------------------------------------------------- | 954| 201 | Permission verification failed. The application does not have the permission required to call the API. | 955| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter type; 3. Parameter verification failed; 4. The size of specified type is greater than 255. | 956 957**示例:** 958 959 ```ts 960 import { distributedDeviceManager } from '@kit.DistributedServiceKit'; 961 import { BusinessError } from '@kit.BasicServicesKit'; 962 963 class Data { 964 deviceName: string = ''; 965 } 966 967 try { 968 let dmInstance = distributedDeviceManager.createDeviceManager('ohos.samples.jsHelloWorld'); 969 dmInstance.on('deviceNameChange', (data: Data) => { 970 console.info('deviceNameChange on:' + JSON.stringify(data)); 971 }); 972 } catch (err) { 973 let e: BusinessError = err as BusinessError; 974 console.error('deviceNameChange errCode:' + e.code + ',errMessage:' + e.message); 975 } 976 ``` 977 978### off('deviceNameChange') 979 980off(type: 'deviceNameChange', callback?: Callback<{ deviceName: string; }>): void 981 982取消注册设备名称变更回调监听。 983 984**需要权限**:ohos.permission.DISTRIBUTED_DATASYNC 985 986**系统能力**:SystemCapability.DistributedHardware.DeviceManager 987 988**参数:** 989 990 | 参数名 | 类型 | 必填 | 说明 | 991 | -------- | ---------------------------------------- | ---- | ------------------------------ | 992 | type | string | 是 | 取消注册设备名称改变回调,固定为deviceNameChange。 | 993 | callback | Callback<{ deviceName: string;}> | 否 | 指示要取消注册设备名称改变的回调方法。 | 994 995**错误码:** 996 997以下的错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。 998 999| 错误码ID | 错误信息 | 1000| -------- | --------------------------------------------------------------- | 1001| 201 | Permission verification failed. The application does not have the permission required to call the API. | 1002| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter type; 3. Parameter verification failed; 4. The size of specified type is greater than 255. | 1003 1004**示例:** 1005 1006 ```ts 1007 import { distributedDeviceManager } from '@kit.DistributedServiceKit'; 1008 import { BusinessError } from '@kit.BasicServicesKit'; 1009 1010 class Data { 1011 deviceName: string = ''; 1012 } 1013 1014 try { 1015 let dmInstance = distributedDeviceManager.createDeviceManager('ohos.samples.jsHelloWorld'); 1016 dmInstance.off('deviceNameChange', (data: Data) => { 1017 console.info('deviceNameChange' + JSON.stringify(data)); 1018 }); 1019 } catch (err) { 1020 let e: BusinessError = err as BusinessError; 1021 console.error('deviceNameChange errCode:' + e.code + ',errMessage:' + e.message); 1022 } 1023 ``` 1024 1025### on('discoverFailure') 1026 1027on(type: 'discoverFailure', callback: Callback<{ reason: number; }>): void 1028 1029注册设备发现失败回调监听。 1030 1031**需要权限**:ohos.permission.DISTRIBUTED_DATASYNC 1032 1033**系统能力**:SystemCapability.DistributedHardware.DeviceManager 1034 1035**参数:** 1036 1037 | 参数名 | 类型 | 必填 | 说明 | 1038 | -------- | ---------------------------------------- | ---- | ------------------------------ | 1039 | type | string | 是 | 注册设备发现失败回调,以便在发现周边设备失败时通知应用程序,固定为discoverFailure。 | 1040 | callback | Callback<{ reason: number; }> | 是 | 注册设备发现失败的回调方法。 | 1041 1042**错误码:** 1043 1044以下的错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。 1045 1046| 错误码ID | 错误信息 | 1047| -------- | --------------------------------------------------------------- | 1048| 201 | Permission verification failed. The application does not have the permission required to call the API. | 1049| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter type; 3. Parameter verification failed; 4. The size of specified type is greater than 255. | 1050 1051**示例:** 1052 1053 ```ts 1054 import { distributedDeviceManager } from '@kit.DistributedServiceKit'; 1055 import { BusinessError } from '@kit.BasicServicesKit'; 1056 1057 class Data { 1058 reason: number = 0; 1059 } 1060 1061 try { 1062 let dmInstance = distributedDeviceManager.createDeviceManager('ohos.samples.jsHelloWorld'); 1063 dmInstance.on('discoverFailure', (data: Data) => { 1064 console.info('discoverFailure on:' + JSON.stringify(data)); 1065 }); 1066 } catch (err) { 1067 let e: BusinessError = err as BusinessError; 1068 console.error('discoverFailure errCode:' + e.code + ',errMessage:' + e.message); 1069 } 1070 ``` 1071 1072### off('discoverFailure') 1073 1074off(type: 'discoverFailure', callback?: Callback<{ reason: number; }>): void 1075 1076取消注册设备发现失败回调。 1077 1078**需要权限**:ohos.permission.DISTRIBUTED_DATASYNC 1079 1080**系统能力**:SystemCapability.DistributedHardware.DeviceManager 1081 1082**参数:** 1083 1084 | 参数名 | 类型 | 必填 | 说明 | 1085 | -------- | ---------------------------------------- | ---- | ----------------- | 1086 | type | string | 是 | 取消注册设备发现失败回调,固定为discoverFailure。 | 1087 | callback | Callback<{ reason: number; }> | 否 | 指示要取消注册的设备发现失败回调。 | 1088 1089**错误码:** 1090 1091以下的错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。 1092 1093| 错误码ID | 错误信息 | 1094| -------- | --------------------------------------------------------------- | 1095| 201 | Permission verification failed. The application does not have the permission required to call the API. | 1096| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter type; 3. Parameter verification failed; 4. The size of specified type is greater than 255. | 1097 1098**示例:** 1099 1100 ```ts 1101 import { distributedDeviceManager } from '@kit.DistributedServiceKit'; 1102 import { BusinessError } from '@kit.BasicServicesKit'; 1103 1104 class Data { 1105 reason: number = 0; 1106 } 1107 1108 try { 1109 let dmInstance = distributedDeviceManager.createDeviceManager('ohos.samples.jsHelloWorld'); 1110 dmInstance.off('discoverFailure', (data: Data) => { 1111 console.info('discoverFailure' + JSON.stringify(data)); 1112 }); 1113 } catch (err) { 1114 let e: BusinessError = err as BusinessError; 1115 console.error('discoverFailure errCode:' + e.code + ',errMessage:' + e.message); 1116 } 1117 ``` 1118 1119### on('serviceDie') 1120 1121on(type: 'serviceDie', callback?: Callback<{}>): void 1122 1123注册设备管理服务死亡回调,以便在服务死亡时通知应用程序。 1124 1125**需要权限**:ohos.permission.DISTRIBUTED_DATASYNC 1126 1127**系统能力**:SystemCapability.DistributedHardware.DeviceManager 1128 1129**参数:** 1130 1131 | 参数名 | 类型 | 必填 | 说明 | 1132 | -------- | ----------------------- | ---- | ---------------------------------------- | 1133 | type | string | 是 | 注册serviceDie回调,以便在devicemanager服务异常终止时通知应用程序,固定为serviceDie。 | 1134 | callback | Callback<{}> | 否 | 注册serviceDie的回调方法。 | 1135 1136**错误码:** 1137 1138以下的错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。 1139 1140| 错误码ID | 错误信息 | 1141| -------- | --------------------------------------------------------------- | 1142| 201 | Permission verification failed. The application does not have the permission required to call the API. | 1143| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter type; 3. Parameter verification failed; 4. The size of specified type is greater than 255. | 1144 1145**示例:** 1146 1147 ```ts 1148 import { distributedDeviceManager } from '@kit.DistributedServiceKit'; 1149 import { BusinessError } from '@kit.BasicServicesKit'; 1150 1151 try { 1152 let dmInstance = distributedDeviceManager.createDeviceManager('ohos.samples.jsHelloWorld'); 1153 dmInstance.on('serviceDie', () => { 1154 console.info('serviceDie on'); 1155 }); 1156 } catch (err) { 1157 let e: BusinessError = err as BusinessError; 1158 console.error('serviceDie errCode:' + e.code + ',errMessage:' + e.message); 1159 } 1160 ``` 1161 1162### off('serviceDie') 1163 1164off(type: 'serviceDie', callback?: Callback<{}>): void 1165 1166取消注册设备管理服务死亡回调。 1167 1168**需要权限**:ohos.permission.DISTRIBUTED_DATASYNC 1169 1170**系统能力**:SystemCapability.DistributedHardware.DeviceManager 1171 1172**参数:** 1173 1174 | 参数名 | 类型 | 必填 | 说明 | 1175 | -------- | ----------------------- | ---- | ---------------------------------------- | 1176 | type | string | 是 | 取消注册serviceDie回调,以便在devicemanager服务异常终止时通知应用程序,固定为serviceDie。 | 1177 | callback | Callback<{}> | 否 | 取消注册serviceDie的回调方法。 | 1178 1179**错误码:** 1180 1181以下的错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。 1182 1183| 错误码ID | 错误信息 | 1184| -------- | --------------------------------------------------------------- | 1185| 201 | Permission verification failed. The application does not have the permission required to call the API. | 1186| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter type; 3. Parameter verification failed; 4. The size of specified type is greater than 255. | 1187 1188**示例:** 1189 1190 ```ts 1191 import { distributedDeviceManager } from '@kit.DistributedServiceKit'; 1192 import { BusinessError } from '@kit.BasicServicesKit'; 1193 1194 try { 1195 let dmInstance = distributedDeviceManager.createDeviceManager('ohos.samples.jsHelloWorld'); 1196 dmInstance.off('serviceDie', () => { 1197 console.info('serviceDie off'); 1198 }); 1199 } catch (err) { 1200 let e: BusinessError = err as BusinessError; 1201 console.error('serviceDie errCode:' + e.code + ',errMessage:' + e.message); 1202 } 1203 ```