OpenHarmony 4.0 release 使用 Sample 仓 中 ArkTSDistributedCalc 项目无法发现远程设备
·
使用 OpenHarmony 4.0 release 最新发布的 release note 中的镜像,使用 rk3568 运行 Sample 仓 中 ArkTSDistributedCalc 项目。
在项目打包前,已修改 SDK 中 配置项目为系统App,应用为 API 10 应用,IDE 使用 OpenHarmony 4.0 release 最新发布的 release note 中的版本。
在 RemoteDeviceModel.ets 文件中,如下代码
export class RemoteDeviceModel { public deviceList: Array<distributedDeviceManager.DeviceBasicInfo> | undefined = undefined public discoverList: Array<distributedDeviceManager.DeviceBasicInfo> = [] private callback: () => void = () => { } private authCallback: () => void = () => { } private deviceManager: distributedDeviceManager.DeviceManager | null = null registerDeviceListCallback(callback: Callback<void>) { Logger.info(TAG, `deviceManager type =${typeof (this.deviceManager)} ,${JSON.stringify(this.deviceManager)} ,${JSON.stringify(this.deviceManager) === '{}'}`) if (typeof (this.deviceManager) !== 'undefined') { this.registerDeviceListCallbackImplement(callback) return } Logger.info(TAG, 'deviceManager.createDeviceManager begin') try { let dmInstance = distributedDeviceManager.createDeviceManager('ohos.samples.etsdistributedcalc'); this.deviceManager = dmInstance this.registerDeviceListCallbackImplement(callback) Logger.info(TAG, `createDeviceManager callback returned, value= ${JSON.stringify(this.deviceManager)}`) } catch (error) { Logger.error(TAG, `createDeviceManager throw code:${error.code} message:${error.message}`) } Logger.info(TAG, 'deviceManager.createDeviceManager end') }this.deviceManager 类型判断为 object,日志如附件。导致程序异常。
为什么定义为 null 的变量在 typeof 时会 输出 为object?
更多推荐
所有评论(0)