【问题标题】:Ionic native barcodescanner not working in Android离子原生条形码扫描仪在 Android 中不起作用
【发布时间】:2019-01-06 21:27:52
【问题描述】:

我有离子项目扫描条形码,我使用 @ionic-native/barcode-scanner 它在 iOS 上工作正常,但在 android 中,当我调用扫描方法时,相机正在打开,当它捕获应用程序崩溃的条形码并转到根页面(登录)。我正在使用 LG Nexus android 6.0,谁能帮帮我!

this.barcodeScanner.scan().then((data) => {
  this.addProduct(data.text);
}, (err) => {
  console.log(err);
});

离子:

离子(离子 CLI):4.0.1(/usr/local/lib/node_modules/ionic)
离子框架:离子角 3.9.2 @ionic/app-scripts: 3.1.10

科尔多瓦:

cordova (Cordova CLI):7.1.0 Cordova 平台:android 7.1.1、浏览器5.0.3、ios 4.5.5

系统:

ios 部署:1.9.2 NodeJS:v6.10.0 (/usr/local/bin/node)
npm:6.2.0 操作系统:macOS High Sierra Xcode: Xcode 9.4.1 构建版本 9F2000

【问题讨论】:

  • 您的代码看起来不错。使用下面的代码并在catch 块中发布它打印的内容。 this.barcodeScanner.scan().then(barcodeData => { console.log('Barcode data', barcodeData); }).catch(err => { console.log('Error', err); });
  • 谢谢,我尝试添加 catch 但没有任何改变,我看到条形码扫描仪本身没有问题,它读取并获取条形码,然后以奇怪的行为关闭当前页面并转到根页面。

标签: ionic-framework ionic3 barcode-scanner


【解决方案1】:

我在 app.component 中添加了 onPauseSubscription,所以当我调用条形码扫描仪时,它只会在 android 中自动调用此事件。我删除了它,它现在可以工作了。

this.onPauseSubscription = platform.pause.subscribe(() => {
    console.log('onPauseSubscription'); // 30 sn
    this.logout();
  });

【讨论】:

    猜你喜欢
    • 2019-05-26
    • 2019-04-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-08-08
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多