bitpay / cordova-plugin-qrscanner

A fast, energy efficient, highly-configurable QR code scanner for Cordova apps and the browser.
MIT License
569 stars 773 forks source link

cordova build ios failed #267

Open wenji-my opened 5 years ago

wenji-my commented 5 years ago

Hello, I can't compile this cordova plugin on Swift 4.1.

/Users/arsa/projects/gitlab/sz-game/wallet-app/src-cordova/platforms/ios/qianbao/Plugins/cordova-plugin-qrscanner/QRScanner.swift:483:16: warning: unnecessary check for 'iOS'; enclosing scope ensures guard will always be true
            if #available(iOS 8.0, *) {
               ^
/Users/arsa/projects/gitlab/sz-game/wallet-app/src-cordova/platforms/ios/qianbao/Plugins/cordova-plugin-qrscanner/QRScanner.swift:470:9: note: enclosing scope here
        if #available(iOS 10.0, *) {
        ^
/Users/arsa/projects/gitlab/sz-game/wallet-app/src-cordova/platforms/ios/qianbao/Plugins/cordova-plugin-qrscanner/QRScanner.swift:33:37: error: value of optional type 'AVCaptureConnection?' not unwrapped; did you mean to use '!' or '?'?
            self.videoPreviewLayer?.connection.videoOrientation = interfaceOrientationToVideoOrientation(UIApplication.shared.statusBarOrientation);
                                    ^
                                              ?
/Users/arsa/projects/gitlab/sz-game/wallet-app/src-cordova/platforms/ios/qianbao/Plugins/cordova-plugin-qrscanner/QRScanner.swift:38:42: error: 'AVLayerVideoGravityResizeAspectFill' has been renamed to 'AVLayerVideoGravity.resizeAspectFill'
            previewLayer!.videoGravity = AVLayerVideoGravityResizeAspectFill
                                         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                                         AVLayerVideoGravity.resizeAspectFill
AVFoundation.AVLayerVideoGravityResizeAspectFill:3:12: note: 'AVLayerVideoGravityResizeAspectFill' was obsoleted in Swift 3
public let AVLayerVideoGravityResizeAspectFill: AVLayerVideoGravity
           ^
/Users/arsa/projects/gitlab/sz-game/wallet-app/src-cordova/platforms/ios/qianbao/Plugins/cordova-plugin-qrscanner/QRScanner.swift:89:64: error: argument of '#selector' refers to instance method 'pageDidLoad()' that is not exposed to Objective-C
        NotificationCenter.default.addObserver(self, selector: #selector(pageDidLoad), name: NSNotification.Name.CDVPageDidLoad, object: nil)
                                                               ^         ~~~~~~~~~~~
/Users/arsa/projects/gitlab/sz-game/wallet-app/src-cordova/platforms/ios/qianbao/Plugins/cordova-plugin-qrscanner/QRScanner.swift:249:10: note: add '@objc' to expose this instance method to Objective-C
    func pageDidLoad() {
         ^
    @objc
/Users/arsa/projects/gitlab/sz-game/wallet-app/src-cordova/platforms/ios/qianbao/Plugins/cordova-plugin-qrscanner/QRScanner.swift:124:57: error: incorrect argument label in call (have 'forMediaType:', expected 'for:')
        let status = AVCaptureDevice.authorizationStatus(forMediaType: AVMediaTypeVideo)
                                                        ^~~~~~~~~~~~~
                                                         for
/Users/arsa/projects/gitlab/sz-game/wallet-app/src-cordova/platforms/ios/qianbao/Plugins/cordova-plugin-qrscanner/QRScanner.swift:136:68: error: incorrect argument label in call (have 'withMediaType:', expected 'for:')
                let availableVideoDevices = AVCaptureDevice.devices(withMediaType: AVMediaTypeVideo)
                                                                   ^~~~~~~~~~~~~~
                                                                    for
/Users/arsa/projects/gitlab/sz-game/wallet-app/src-cordova/platforms/ios/qianbao/Plugins/cordova-plugin-qrscanner/QRScanner.swift:154:43: error: value of optional type 'AVCaptureMetadataOutput?' not unwrapped; did you mean to use '!' or '?'?
                captureSession!.addOutput(metaOutput)
                                          ^
                                                    !
/Users/arsa/projects/gitlab/sz-game/wallet-app/src-cordova/platforms/ios/qianbao/Plugins/cordova-plugin-qrscanner/QRScanner.swift:156:52: error: use of unresolved identifier 'AVMetadataObjectTypeQRCode'
                metaOutput!.metadataObjectTypes = [AVMetadataObjectTypeQRCode]
                                                   ^~~~~~~~~~~~~~~~~~~~~~~~~~
AVFoundation.AVMetadataObjectTypeFace:3:12: note: did you mean 'AVMetadataObjectTypeFace'?
public let AVMetadataObjectTypeFace: AVMetadataObject.ObjectType
           ^
AVFoundation.AVMetadataObjectType:3:18: note: did you mean 'AVMetadataObjectType'?
public typealias AVMetadataObjectType = AVMetadataObject.ObjectType
                 ^
/Users/arsa/projects/gitlab/sz-game/wallet-app/src-cordova/platforms/ios/qianbao/Plugins/cordova-plugin-qrscanner/QRScanner.swift:157:80: error: value of optional type 'AVCaptureSession?' not unwrapped; did you mean to use '!' or '?'?
                captureVideoPreviewLayer = AVCaptureVideoPreviewLayer(session: captureSession)
                                                                               ^
                                                                                             !
/Users/arsa/projects/gitlab/sz-game/wallet-app/src-cordova/platforms/ios/qianbao/Plugins/cordova-plugin-qrscanner/QRScanner.swift:213:23: error: 'AVCaptureTorchMode' has been renamed to 'AVCaptureDevice.TorchMode'
        var useMode = AVCaptureTorchMode.on
                      ^~~~~~~~~~~~~~~~~~
                      AVCaptureDevice.TorchMode
AVFoundation.AVCaptureTorchMode:3:18: note: 'AVCaptureTorchMode' was obsoleted in Swift 4
public typealias AVCaptureTorchMode = AVCaptureDevice.TorchMode
                 ^
/Users/arsa/projects/gitlab/sz-game/wallet-app/src-cordova/platforms/ios/qianbao/Plugins/cordova-plugin-qrscanner/QRScanner.swift:241:26: error: use of unresolved identifier 'AVMetadataObjectTypeQRCode'
        if found.type == AVMetadataObjectTypeQRCode && found.stringValue != nil {
                         ^~~~~~~~~~~~~~~~~~~~~~~~~~
AVFoundation.AVMetadataObjectTypeFace:3:12: note: did you mean 'AVMetadataObjectTypeFace'?
public let AVMetadataObjectTypeFace: AVMetadataObject.ObjectType
           ^
AVFoundation.AVMetadataObjectType:3:18: note: did you mean 'AVMetadataObjectType'?
public typealias AVMetadataObjectType = AVMetadataObject.ObjectType
                 ^
/Users/arsa/projects/gitlab/sz-game/wallet-app/src-cordova/platforms/ios/qianbao/Plugins/cordova-plugin-qrscanner/QRScanner.swift:257:57: error: incorrect argument label in call (have 'forMediaType:', expected 'for:')
        let status = AVCaptureDevice.authorizationStatus(forMediaType: AVMediaTypeVideo)
                                                        ^~~~~~~~~~~~~
                                                         for
/Users/arsa/projects/gitlab/sz-game/wallet-app/src-cordova/platforms/ios/qianbao/Plugins/cordova-plugin-qrscanner/QRScanner.swift:260:42: error: incorrect argument label in call (have 'forMediaType:completionHandler:', expected 'for:completionHandler:')
            AVCaptureDevice.requestAccess(forMediaType: AVMediaTypeVideo, completionHandler: { (granted) -> Void in
                                         ^~~~~~~~~~~~~
                                          for
/Users/arsa/projects/gitlab/sz-game/wallet-app/src-cordova/platforms/ios/qianbao/Plugins/cordova-plugin-qrscanner/QRScanner.swift:308:35: error: value of optional type 'AVCaptureConnection?' not unwrapped; did you mean to use '!' or '?'?
        captureVideoPreviewLayer?.connection.isEnabled = false
                                  ^
                                            ?
/Users/arsa/projects/gitlab/sz-game/wallet-app/src-cordova/platforms/ios/qianbao/Plugins/cordova-plugin-qrscanner/QRScanner.swift:317:35: error: value of optional type 'AVCaptureConnection?' not unwrapped; did you mean to use '!' or '?'?
        captureVideoPreviewLayer?.connection.isEnabled = true
                                  ^
                                            ?
/Users/arsa/projects/gitlab/sz-game/wallet-app/src-cordova/platforms/ios/qianbao/Plugins/cordova-plugin-qrscanner/QRScanner.swift:398:70: error: incorrect argument label in call (have 'forMediaType:', expected 'for:')
        let authorizationStatus = AVCaptureDevice.authorizationStatus(forMediaType: AVMediaTypeVideo);
                                                                     ^~~~~~~~~~~~~
                                                                      for
/Users/arsa/projects/gitlab/sz-game/wallet-app/src-cordova/platforms/ios/qianbao/Plugins/cordova-plugin-qrscanner/QRScanner.swift:422:52: error: value of optional type 'AVCaptureConnection?' not unwrapped; did you mean to use '!' or '?'?
            previewing = captureVideoPreviewLayer!.connection.isEnabled
                                                   ^
                                                             ?
/Users/huang_wen_ji/projects/gitlab/sz-game/wallet-app/src-cordova/platforms/ios/qianbao/Plugins/cordova-plugin-qrscanner/QRScanner.swift:431:37: error: 'AVCaptureTorchMode' has been renamed to 'AVCaptureDevice.TorchMode'
        if(backCamera?.torchMode == AVCaptureTorchMode.on){
                                    ^~~~~~~~~~~~~~~~~~
                                    AVCaptureDevice.TorchMode
AVFoundation.AVCaptureTorchMode:3:18: note: 'AVCaptureTorchMode' was obsoleted in Swift 4
public typealias AVCaptureTorchMode = AVCaptureDevice.TorchMode
                 ^
/Users/arsa/projects/gitlab/sz-game/wallet-app/src-cordova/platforms/ios/qianbao/Plugins/cordova-plugin-qrscanner/QRScanner.swift:441:117: error: 'AVCaptureTorchMode' has been renamed to 'AVCaptureDevice.TorchMode'
        if(backCamera?.hasTorch == true && backCamera?.isTorchAvailable == true && backCamera?.isTorchModeSupported(AVCaptureTorchMode.on) == true){
                                                                                                                    ^~~~~~~~~~~~~~~~~~
                                                                                                                    AVCaptureDevice.TorchMode
AVFoundation.AVCaptureTorchMode:3:18: note: 'AVCaptureTorchMode' was obsoleted in Swift 4
public typealias AVCaptureTorchMode = AVCaptureDevice.TorchMode
                 ^

** BUILD FAILED **

The following build commands failed:
        CompileSwift normal x86_64 /Users/arsa/projects/gitlab/sz-game/wallet-app/src-cordova/platforms/ios/qianbao/Plugins/cordova-plugin-qrscanner/QRScanner.swift
        CompileSwiftSources normal x86_64 com.apple.xcode.tools.swift.compiler
(2 failures)

please help, Thanks!

ireade commented 5 years ago

I'm also having the same issue. When I run the following command I get the same error message as above.

ionic cordova build ios -- --buildFlag="-UseModernBuildSystem=0"

My ionic info:

Ionic:

   Ionic CLI                     : 5.0.3 (/usr/local/lib/node_modules/ionic)
   Ionic Framework               : @ionic/angular 4.4.2
   @angular-devkit/build-angular : 0.13.8
   @angular-devkit/schematics    : 0.7.5
   @angular/cli                  : 7.3.8
   @ionic/angular-toolkit        : not installed

Cordova:

   Cordova CLI       : 8.1.2 (cordova-lib@8.1.1)
   Cordova Platforms : android 8.0.0, browser 5.0.4, ios 4.5.5
   Cordova Plugins   : cordova-plugin-ionic-keyboard 2.1.3, cordova-plugin-ionic-webview 2.2.0, (and 16 other plugins)

Utility:

   cordova-res : not installed
   native-run  : not installed

System:

   Android SDK Tools : 26.1.1 (/Users/ireaderinokun/Library/Android/sdk)
   NodeJS            : v10.16.0 (/usr/local/bin/node)
   npm               : 6.9.0
   OS                : macOS Mojave
   Xcode             : Xcode 10.2.1 Build version 10E1001

I'm also using Swift language version 5, as set in my config.xml

<preference name="UseSwiftLanguageVersion" value="5" />
itismelito commented 4 years ago

@ireade have you found any solution yet, i have the same issue.

ireade commented 4 years ago

@itismelito Yes! I don't remember exactly which of these things worked, but here's my current setup:

My ionic info:

Ionic:

   Ionic CLI                     : 5.0.3 (/usr/local/lib/node_modules/ionic)
   Ionic Framework               : @ionic/angular 4.4.2
   @angular-devkit/build-angular : 0.13.8
   @angular-devkit/schematics    : 0.7.5
   @angular/cli                  : 7.3.8
   @ionic/angular-toolkit        : not installed

Cordova:

   Cordova CLI       : 8.1.2 (cordova-lib@8.1.1)
   Cordova Platforms : android 8.0.0, browser 5.0.4, ios 4.5.5
   Cordova Plugins   : cordova-plugin-ionic-keyboard 2.1.3, cordova-plugin-ionic-webview 2.5.1, (and 16 other plugins)

Utility:

   cordova-res : not installed
   native-run  : not installed

System:

   Android SDK Tools : 26.1.1 (/Users/ireaderinokun/Library/Android/sdk)
   ios-deploy        : 1.9.4
   NodeJS            : v10.16.0 (/usr/local/bin/node)
   npm               : 6.9.0
   OS                : macOS Mojave
   Xcode             : Xcode 10.1 Build version 10B61

Also:

Hope that helps!

ronamanfredini commented 4 years ago

I had the same problem... to use this plugin with the most recent version of XCode, you have to replace a method on the QRScanner.swift file, located at Users/arsa/projects/gitlab/sz-game/wallet-app/src-cordova/platforms/ios/qianbao/Plugins/cordova-plugin-qrscanner/QRScanner.swift

Just replace

@objc func openSettings(_ command: CDVInvokedUrlCommand) {
    if #available(iOS 10.0, *) {
        guard let settingsUrl = URL(string: UIApplication.openSettingsURLString) else {
        return
    }
    if UIApplication.shared.canOpenURL(settingsUrl) {
        UIApplication.shared.open(settingsUrl, completionHandler: { (success) in
            self.getStatus(command)
        })
    } else {
        self.sendErrorCode(command: command, error: QRScannerError.open_settings_unavailable)
        }
    } else {
        // pre iOS 10.0
        if #available(iOS 8.0, *) {
            UIApplication.shared.openURL(NSURL(string: UIApplication.openSettingsURLString)! as URL)
            self.getStatus(command)
        } else {
            self.sendErrorCode(command: command, error: QRScannerError.open_settings_unavailable)
        }
    }
}

With this:

@objc func openSettings(_ command: CDVInvokedUrlCommand) {
        if #available(iOS 10.0, *) {
            guard let settingsUrl = URL(string: UIApplicationOpenSettingsURLString) else {
            return
        }
        if UIApplication.shared.canOpenURL(settingsUrl) {
            UIApplication.shared.open(settingsUrl, completionHandler: { (success) in
                self.getStatus(command)
            })
        } else {
            self.sendErrorCode(command: command, error: QRScannerError.open_settings_unavailable)
            }
        } else {
            // pre iOS 10.0
            if #available(iOS 8.0, *) {
                UIApplication.shared.openURL(NSURL(string: UIApplicationOpenSettingsURLString)! as URL)
                self.getStatus(command)
            } else {
                self.sendErrorCode(command: command, error: QRScannerError.open_settings_unavailable)
            }
        }
    }

Try it and see if it helps