cordova-plugin-qrscanner: iOS can't compile on Xcode 10.2.1 Swift 5/4.2/4
Hi!
I can’t compile this cordova plugin on Xcode 10.2.1 and I tried with Swift 5/4.2 and 4.
/Users/user/Documents/Mobile/platforms/ios/project/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/user/Documents/Mobile/platforms/ios/project/Plugins/cordova-plugin-qrscanner/QRScanner.swift:470:9: note: enclosing scope here
if #available(iOS 10.0, *) {
^
/Users/user/Documents/Mobile/platforms/ios/project/Plugins/cordova-plugin-qrscanner/QRScanner.swift:33:37: error: value of optional type 'AVCaptureConnection?' must be unwrapped to refer to member 'videoOrientation' of wrapped base type 'AVCaptureConnection'
self.videoPreviewLayer?.connection.videoOrientation = interfaceOrientationToVideoOrientation(UIApplication.shared.statusBarOrientation);
^
/Users/user/Documents/Mobile/platforms/ios/project/Plugins/cordova-plugin-qrscanner/QRScanner.swift:33:37: note: chain the optional using '?' to access member 'videoOrientation' only for non-'nil' base values
self.videoPreviewLayer?.connection.videoOrientation = interfaceOrientationToVideoOrientation(UIApplication.shared.statusBarOrientation);
^
?
/Users/user/Documents/Mobile/platforms/ios/project/Plugins/cordova-plugin-qrscanner/QRScanner.swift:33:37: note: force-unwrap using '!' to abort execution if the optional value contains 'nil'
self.videoPreviewLayer?.connection.videoOrientation = interfaceOrientationToVideoOrientation(UIApplication.shared.statusBarOrientation);
^
!
/Users/user/Documents/Mobile/platforms/ios/project/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/user/Documents/Mobile/platforms/ios/project/Plugins/cordova-plugin-qrscanner/QRScanner.swift:249:10: note: add '@objc' to expose this instance method to Objective-C
func pageDidLoad() {
^
@objc
/Users/user/Documents/Mobile/platforms/ios/project/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/user/Documents/Mobile/platforms/ios/project/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/user/Documents/Mobile/platforms/ios/project/Plugins/cordova-plugin-qrscanner/QRScanner.swift:154:43: error: value of optional type 'AVCaptureMetadataOutput?' must be unwrapped to a value of type 'AVCaptureMetadataOutput'
captureSession!.addOutput(metaOutput)
^
/Users/user/Documents/Mobile/platforms/ios/project/Plugins/cordova-plugin-qrscanner/QRScanner.swift:154:43: note: coalesce using '??' to provide a default when the optional value contains 'nil'
captureSession!.addOutput(metaOutput)
^
?? <#default value#>
/Users/user/Documents/Mobile/platforms/ios/project/Plugins/cordova-plugin-qrscanner/QRScanner.swift:154:43: note: force-unwrap using '!' to abort execution if the optional value contains 'nil'
captureSession!.addOutput(metaOutput)
^
!
/Users/user/Documents/Mobile/platforms/ios/project/Plugins/cordova-plugin-qrscanner/QRScanner.swift:157:80: error: value of optional type 'AVCaptureSession?' must be unwrapped to a value of type 'AVCaptureSession'
captureVideoPreviewLayer = AVCaptureVideoPreviewLayer(session: captureSession)
^
/Users/user/Documents/Mobile/platforms/ios/project/Plugins/cordova-plugin-qrscanner/QRScanner.swift:157:80: note: coalesce using '??' to provide a default when the optional value contains 'nil'
captureVideoPreviewLayer = AVCaptureVideoPreviewLayer(session: captureSession)
^
?? <#default value#>
/Users/user/Documents/Mobile/platforms/ios/project/Plugins/cordova-plugin-qrscanner/QRScanner.swift:157:80: note: force-unwrap using '!' to abort execution if the optional value contains 'nil'
captureVideoPreviewLayer = AVCaptureVideoPreviewLayer(session: captureSession)
^
!
/Users/user/Documents/Mobile/platforms/ios/project/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/user/Documents/Mobile/platforms/ios/project/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/user/Documents/Mobile/platforms/ios/project/Plugins/cordova-plugin-qrscanner/QRScanner.swift:308:35: error: value of optional type 'AVCaptureConnection?' must be unwrapped to refer to member 'isEnabled' of wrapped base type 'AVCaptureConnection'
captureVideoPreviewLayer?.connection.isEnabled = false
^
/Users/user/Documents/Mobile/platforms/ios/project/Plugins/cordova-plugin-qrscanner/QRScanner.swift:308:35: note: chain the optional using '?' to access member 'isEnabled' only for non-'nil' base values
captureVideoPreviewLayer?.connection.isEnabled = false
^
?
/Users/user/Documents/Mobile/platforms/ios/project/Plugins/cordova-plugin-qrscanner/QRScanner.swift:308:35: note: force-unwrap using '!' to abort execution if the optional value contains 'nil'
captureVideoPreviewLayer?.connection.isEnabled = false
^
!
/Users/user/Documents/Mobile/platforms/ios/project/Plugins/cordova-plugin-qrscanner/QRScanner.swift:317:35: error: value of optional type 'AVCaptureConnection?' must be unwrapped to refer to member 'isEnabled' of wrapped base type 'AVCaptureConnection'
captureVideoPreviewLayer?.connection.isEnabled = true
^
/Users/user/Documents/Mobile/platforms/ios/project/Plugins/cordova-plugin-qrscanner/QRScanner.swift:317:35: note: chain the optional using '?' to access member 'isEnabled' only for non-'nil' base values
captureVideoPreviewLayer?.connection.isEnabled = true
^
?
/Users/user/Documents/Mobile/platforms/ios/project/Plugins/cordova-plugin-qrscanner/QRScanner.swift:317:35: note: force-unwrap using '!' to abort execution if the optional value contains 'nil'
captureVideoPreviewLayer?.connection.isEnabled = true
^
!
/Users/user/Documents/Mobile/platforms/ios/project/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/user/Documents/Mobile/platforms/ios/project/Plugins/cordova-plugin-qrscanner/QRScanner.swift:422:52: error: value of optional type 'AVCaptureConnection?' must be unwrapped to refer to member 'isEnabled' of wrapped base type 'AVCaptureConnection'
previewing = captureVideoPreviewLayer!.connection.isEnabled
^
/Users/user/Documents/Mobile/platforms/ios/project/Plugins/cordova-plugin-qrscanner/QRScanner.swift:422:52: note: chain the optional using '?' to access member 'isEnabled' only for non-'nil' base values
previewing = captureVideoPreviewLayer!.connection.isEnabled
^
?
/Users/user/Documents/Mobile/platforms/ios/project/Plugins/cordova-plugin-qrscanner/QRScanner.swift:422:52: note: force-unwrap using '!' to abort execution if the optional value contains 'nil'
previewing = captureVideoPreviewLayer!.connection.isEnabled
^
!
** BUILD FAILED **
The following build commands failed:
CompileSwift normal x86_64 /Users/user/Documents/Mobile/platforms/ios/project/Plugins/cordova-plugin-qrscanner/QRScanner.swift
CompileSwiftSources normal x86_64 com.apple.xcode.tools.swift.compiler
(2 failures)
xcodebuild: Command failed with exit code 65
If I delete this plugin from cordova and compile again it will work perfectly fine. I’m using the last version available on NPM (3.0.1) of this plugin.
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 11
- Comments: 18 (1 by maintainers)
Hi Bruce, Please change UIApplication.openSettingsURLString to be UIApplicationOpenSettingsURLString and add this part <preference ` name=“UseSwiftLanguageVersion” value=“5” /> inside platform “ios”
The only thing that solved the issue on my case was to downgrade my xcode version, so I could generate the build without issues. Xcode Version: 10.1