我想在我的应用程序中使用QrScanner。所以我安装了
ionic cordova plugin add cordova-plugin-qrscanner
npm install --save @ionic-native/qr-scanner@beta
插件,然后执行离子Cordova运行浏览器,然后在手机中访问生成的URL。每当我尝试打开qr扫描仪时,它始终显示camera is not available
。即使我的手机带有摄像头,我也在android和ios中进行了测试,但是结果是相同的。这是我的代码
this.qrScanner.prepare()
.then((status: QRScannerStatus) => {
if (status.authorized) {
// camera permission was granted
// start scanning
const scanSub = this.qrScanner.scan().subscribe((text: string) => {
console.log('Scanned something', text);
this.sharedAlertService.presentBasicAlert('Authorized', '', JSON.stringify(text));
this.qrScanner.hide(); // hide camera preview
scanSub.unsubscribe(); // stop scanning
});
} else if (status.denied) {
this.sharedAlertService.presentBasicAlert('Denied', '', 'No permission');
// camera permission was permanently denied
// you must use QRScanner.openSettings() method to guide the user to the settings page
// then they can grant the permission from there
} else {
// permission was denied, but not permanently. You can ask for permission again at a later time.
}
})
.catch((e: any) => this.sharedAlertService.presentBasicAlert('Error', '', JSON.stringify(e)));
在浏览器中访问qr扫描仪有什么解决方案?谢谢。
答案 0 :(得分:1)
浏览器本身不支持“相机”,因此您本机使用它有点不走运。最好的选择是为浏览器创建模拟数据,该模拟数据将使用该模拟数据进行模拟,并返回虚拟数据。
Ionic对此有an article,可以更深入地解释它。