1e41f4b71Sopenharmony_ci# UIServiceHostProxy (系统接口) 2e41f4b71Sopenharmony_ci 3e41f4b71Sopenharmony_ciUIServiceHostProxy提供代理能力,可以将数据从[UIServiceExtension](js-apis-app-ability-uiServiceExtensionAbility-sys.md)服务端发送到客户端。 4e41f4b71Sopenharmony_ci 5e41f4b71Sopenharmony_ci 6e41f4b71Sopenharmony_ci> **说明:** 7e41f4b71Sopenharmony_ci> 8e41f4b71Sopenharmony_ci> - 本模块首批接口从API version 13开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 9e41f4b71Sopenharmony_ci> - 本模块接口仅可在Stage模型下使用。 10e41f4b71Sopenharmony_ci> - 本模块接口需要在主线程中使用,不要在Worker、TaskPool等子线程中使用。 11e41f4b71Sopenharmony_ci> - 本模块接口为系统接口。 12e41f4b71Sopenharmony_ci 13e41f4b71Sopenharmony_ci## 导入模块 14e41f4b71Sopenharmony_ci 15e41f4b71Sopenharmony_ci```ts 16e41f4b71Sopenharmony_ciimport { common } from '@kit.AbilityKit'; 17e41f4b71Sopenharmony_ci``` 18e41f4b71Sopenharmony_ci 19e41f4b71Sopenharmony_ci 20e41f4b71Sopenharmony_ci## UIServiceHostProxy.sendData 21e41f4b71Sopenharmony_ci 22e41f4b71Sopenharmony_cisendData(data: Record\<string, Object>): void 23e41f4b71Sopenharmony_ci 24e41f4b71Sopenharmony_ci从[UIServiceExtension](js-apis-app-ability-uiServiceExtensionAbility-sys.md)服务端给客户端发送数据。 25e41f4b71Sopenharmony_ci 26e41f4b71Sopenharmony_ci 27e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Ability.AbilityRuntime.Core 28e41f4b71Sopenharmony_ci 29e41f4b71Sopenharmony_ci**系统接口**: 此接口为系统接口。 30e41f4b71Sopenharmony_ci 31e41f4b71Sopenharmony_ci**参数:** 32e41f4b71Sopenharmony_ci 33e41f4b71Sopenharmony_ci| 参数名 | 类型 | 只读 | 可选 | 说明 | 34e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | -------- | 35e41f4b71Sopenharmony_ci| data | Record\<string, Object> | 是 | 否 | 待发送到[UIServiceExtension](js-apis-app-ability-uiServiceExtensionAbility-sys.md)客户端的数据。 | 36e41f4b71Sopenharmony_ci 37e41f4b71Sopenharmony_ci**错误码:** 38e41f4b71Sopenharmony_ci 39e41f4b71Sopenharmony_ci以下错误码详细介绍请参考[通用错误码](../errorcode-universal.md)和[元能力子系统错误码](errorcode-ability.md)。 40e41f4b71Sopenharmony_ci 41e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 42e41f4b71Sopenharmony_ci| ------- | -------------------------------- | 43e41f4b71Sopenharmony_ci| 202 | Not System App. Interface caller is not a system app . | 44e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 45e41f4b71Sopenharmony_ci| 16000050 | Internal error. | 46e41f4b71Sopenharmony_ci 47e41f4b71Sopenharmony_ci**示例:** 48e41f4b71Sopenharmony_ci 49e41f4b71Sopenharmony_ci```ts 50e41f4b71Sopenharmony_ciimport { common, UIServiceExtensionAbility } from '@kit.AbilityKit'; 51e41f4b71Sopenharmony_ci 52e41f4b71Sopenharmony_ciconst TAG: string = '[UiServiceExtensionAbility] '; 53e41f4b71Sopenharmony_ci 54e41f4b71Sopenharmony_ciexport default class MyUiServiceExtensionAbility extends UIServiceExtensionAbility { 55e41f4b71Sopenharmony_ci 56e41f4b71Sopenharmony_ci // 数据发送处理 57e41f4b71Sopenharmony_ci onData(proxy: common.UIServiceHostProxy, data: Record<string, Object>) { 58e41f4b71Sopenharmony_ci console.log(TAG + `onData ${JSON.stringify(data)}`); 59e41f4b71Sopenharmony_ci // 定义发送数据内容 60e41f4b71Sopenharmony_ci let formData: Record<string, string> = { 61e41f4b71Sopenharmony_ci 'proxyData': 'proxyData' 62e41f4b71Sopenharmony_ci }; 63e41f4b71Sopenharmony_ci try { 64e41f4b71Sopenharmony_ci // 发送数据到UIServiceExtension的服务端 65e41f4b71Sopenharmony_ci proxy.sendData(formData); 66e41f4b71Sopenharmony_ci } catch (err) { 67e41f4b71Sopenharmony_ci console.log(TAG + `sendData failed ${JSON.stringify(err.message)}`); 68e41f4b71Sopenharmony_ci } 69e41f4b71Sopenharmony_ci } 70e41f4b71Sopenharmony_ci} 71e41f4b71Sopenharmony_ci``` 72e41f4b71Sopenharmony_ci 73