代码片段:
async onPageShow() {
await this.requestCameraPermission();
let options: scanBarcode.ScanOptions = {
scanTypes: [scanCore.ScanType.ALL],
enableMultiMode: true,
enableAlbum: true
}
this.setDisplay();
try {
customScan.init(options);
} catch (error) {
hilog.error(0x0001, this.TAG, 'init fail, error: %{public}s ', JSON.stringify(error));
}
}
运行后customScan.init报错1000500001。
由于未在module.json5添加相机权限导致if (this.userGrant)这里判断没有正确初始化XComponent,最终导致customScan.init失败,请再添加完权限后试试参考: