使用cordova-plugin-qrscanner报错

报错内容

/Users/mac/Desktop/cordovaProject/azmobile_ionic4_tabs/platforms/ios/AZMobile/Plugins/cordova-plugin-qrscanner/QRScanner.swift:470:9: note: enclosing scope here
        if #available(iOS 10.0, *) {
        ^
/Users/mac/Desktop/cordovaProject/azmobile_ionic4_tabs/platforms/ios/AZMobile/Plugins/cordova-plugin-qrscanner/QRScanner.swift:136:62: warning: 'devices(for:)' was deprecated in iOS 10.0: Use AVCaptureDeviceDiscoverySession instead.
                let availableVideoDevices =  AVCaptureDevice.devices(for: AVMediaType.video)
                                                             ^
/Users/mac/Desktop/cordovaProject/azmobile_ionic4_tabs/platforms/ios/AZMobile/Plugins/cordova-plugin-qrscanner/QRScanner.swift:471:63: error: 'openSettingsURLString' has been renamed to 'UIApplicationOpenSettingsURLString'
            guard let settingsUrl = URL(string: UIApplication.openSettingsURLString) else {
                                                              ^~~~~~~~~~~~~~~~~~~~~
                                                              UIApplicationOpenSettingsURLString
UIKit.UIApplication:70:22: note: 'openSettingsURLString' was introduced in Swift 4.2
    public class let openSettingsURLString: String
                     ^
/Users/mac/Desktop/cordovaProject/azmobile_ionic4_tabs/platforms/ios/AZMobile/Plugins/cordova-plugin-qrscanner/QRScanner.swift:484:74: error: 'openSettingsURLString' has been renamed to 'UIApplicationOpenSettingsURLString'
                UIApplication.shared.openURL(NSURL(string: UIApplication.openSettingsURLString)! as URL)
                                                                         ^~~~~~~~~~~~~~~~~~~~~
                                                                         UIApplicationOpenSettingsURLString
UIKit.UIApplication:70:22: note: 'openSettingsURLString' was introduced in Swift 4.2
    public class let openSettingsURLString: String

这是因为swift再高版本中已经替换了一些函数.而插件里边还没有更新..

解决办法. 插件中搜索 UIApplication.openSettingsURLString

替换成 UIApplicationOpenSettingsURLString 重新编译即可

 

 

1 扫码页面黑屏

1) src -> index.js。修改代码如下

<ion-app style="background: none transparent;"></ion-app>


2)src -> theme -> variables.scss

// qrScanner
ion-app.cameraView, ion-app.cameraView ion-content, ion-app.cameraView .nav-decor {
  background: transparent none !important;
  .tabbar.show-tabbar{
    opacity: 0;
  }
}
[app-viewport],
[overlay-portal],
[nav-viewport],
[tab-portal],
.nav-decor {
  display: none !important;
  background: none transparent !important;
}
html,

body.transparent-body,

.transparent-body,

.transparent-body ion-app,

.transparent-body .app-root,

.transparent-body ion-nav,

.transparent-body .ion-page,

.transparent-body .nav-decor,

.transparent-body ion-content,

.transparent-body .viewscan,

.transparent-body .fixed-content,

.transparent-body .scroll-content {

  background-color: transparent !important;

  background: transparent none!important;
}    

 

多次扫码后摄像头发热的问题

 

this.qrScanner.hide(); // hide camera
this.qrScanner.destroy();  // destory camera 

 

2 QR Scanner安卓不能扫码条形码问题

此问题乃是编码格式的问题,扩充编码格式即可解决。
解决办法: 全局搜索formatList。找到QRScanner.java文件,定位到458行。

formatList.add(BarcodeFormat.UPC_A);
formatList.add(BarcodeFormat.UPC_E);
formatList.add(BarcodeFormat.EAN_13);
formatList.add(BarcodeFormat.EAN_8);
formatList.add(BarcodeFormat.CODE_39);
formatList.add(BarcodeFormat.CODE_93);
formatList.add(BarcodeFormat.CODE_128);
formatList.add(BarcodeFormat.ITF);
formatList.add(BarcodeFormat.DATA_MATRIX);


修改源代码后。要重新构建安卓平台

ionic cordova platform remove android
ionic cordova platform add android

 

3 QR Scanner IOS不能扫码条形码问题

此问题乃是编码格式的问题,扩充编码格式即可解决。
解决办法:全局搜索metadataObjectTypes,找到QRScanner.swift文件,定位到156H

metaOutput!.metadataObjectTypes = [AVMetadataObjectTypeQRCode, AVMetadataObjectTypeEAN13Code, AVMetadataObjectTypeEAN8Code, AVMetadataObjectTypeCode128Code, AVMetadataObjectTypeInterleaved2of5Code]


定位到241H

if [AVMetadataObjectTypeQRCode, AVMetadataObjectTypeEAN13Code, AVMetadataObjectTypeEAN8Code, AVMetadataObjectTypeCode128Code, AVMetadataObjectTypeInterleaved2of5Code].contains(found.type) && found.stringValue != nil {
    scanning = false
    let pluginResult = CDVPluginResult(status: CDVCommandStatus_OK, messageAs: found.stringValue)
    commandDelegate!.send(pluginResult, callbackId: nextScanningCommand?.callbackId!)
    nextScanningCommand = nil
}

 

4 cordova-plugin-crosswalk-webview插件与QR插件冲突,导致黑屏

src -> index.js。修改代码如下

<preference name="CrosswalkAnimatable" value="true" />

 

5 第一次进入扫描页面时页面没有透明,第二次正常

把代码放入ionViewDidEnter。当进入页面时触发

ionViewDidEnter() {
   (window.document.querySelector('ion-app') as HTMLElement).classList.add('cameraView'); 
        this.isShow = true; 
        var cs = (window.document.querySelector('ion-app') as HTMLElement).classList.contains('cameraView');
        console.log(cs);
    }
}

 

 

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值