我指的是https://www.npmjs.com/package/cordova-plugin-qrscanner并嘗試在我的移動應用程式中創建 QR 掃描功能。
因此,對于第一步,我在我的 ts 檔案中創建以下代碼:
function onDone(err, status){
if (err) {
// here we can handle errors and clean up any loose ends.
console.error(err);
}
if (status.authorized) {
// W00t, you have camera access and the scanner is initialized.
// QRscanner.show() should feel very fast.
} else if (status.denied) {
// The video preview will remain black, and scanning is disabled. We can
// try to ask the user to change their mind, but we'll have to send them
// to their device settings with `QRScanner.openSettings()`.
} else {
// we didn't get permission, but we didn't get permanently denied. (On
// Android, a denial isn't permanent unless the user checks the "Don't
// ask again" box.) We can ask again at the next relevant opportunity.
}
}
QRScanner.prepare(onDone);
但是,當我嘗試構建時出現錯誤。
TS2304:找不到名稱“QRScanner”
以下是我的版本:
- 角 CLI:10.2.3
- 節點:10.16.3
- 作業系統:linux x64
- 角度:10.2.5
- npm 版本:6.9.0
我在 package.json 中的 cordova-plugin-qrscanner 版本是:
"@types/cordova-plugin-qrscanner": "^1.0.31",
"cordova-plugin-qrscanner": "^3.0.1",
uj5u.com熱心網友回復:
再會,
我找到了解決方案,以下是我的一些理解。此代碼適用于舊版本的 angular。我使用 angular 10,因此,需要先定義QRScanner物件。這是:
declare var QRScanner: any;
或用于( < any > window).QRScanner獲取 QRScanner 插件的訪問權限。
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/440567.html
上一篇:https://localhost/***/api/get**.php?TOKEN=???:0未知錯誤的Http失敗回應
