中国优质的IT技术网站
专业IT技术创作平台
IT职业在线教育平台
如何接收其他设备通过分布式对象同步的资产?
微信扫码分享
import distributedDataObject from '@ohos.data.distributedDataObject'; import commonType from '@ohos.data.commonType'; class People { name: string|undefined age: number |undefined= 0 attachment: commonType.Asset | undefined constructor(name: string|undefined, age: number|undefined) { this.name = name this.age = age } } @Entry @Component struct Index { build() { Column() { Button("接收资产").onClick(() => { let people = new People(undefined,undefined) people.attachment = undefined let remoteObject: distributedDataObject.DataObject = distributedDataObject.create(getContext(this), people); remoteObject.on('change', (sessionId: string, fields: Array<string>) => { if (fields.includes('attachment')) { // 接收端监听到资产类型属性的数据变更时,代表其所描述的资产文件同步完成 console.info('attachment synchronization completed'); } }); remoteObject.setSessionId('123456'); }) } .width('100%') .height('100%') .justifyContent(FlexAlign.Center) } }