bitpay / cordova-plugin-qrscanner

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

Swift 4 version of the plugin? #227

Open dickverweij opened 5 years ago

dickverweij commented 5 years ago

Hi, swift 3.x is depricated. Is there a swift 4 version of this plugin available?

Razorholt commented 5 years ago

That would be great! I love that plugin but I can't use it in iOS... Please?

RobbertWolfs commented 5 years ago

already swift version 5 since yesterday...

lucapale commented 5 years ago

The plugin does not compile anymore on iOS and XCode 10.2. Swift 3 is deprecated and changing to Swift 4 gets many errors. Is there any plan to upgrade?

tehlothi commented 5 years ago

I went to spin off a new build today as well and after updating to XCode 10.2 I was forced to use at least Swift 4. When choosing Swift 4, 4.2, and 5 I got errors exclusively from this plugin that weren't there prior to switching Swift build version.

EDIT: Tried my Android build and it is working as usual, can confirm all the errors that I am now receiving for the IOS build are coming from the QRScanner.swift file.

Razorholt commented 5 years ago

So, is it my understanding that, as of right now, that plugin is not going to work for iOS using Phonegap Build?

mernen commented 5 years ago

It won't work if you use the newly-released Xcode 10.2. As a workaround, you can download an older version of Xcode here (search for "Xcode 10.1"). To use it for command-line builds, run the following command:

xcode-select --switch <path to the old Xcode.app>/Contents/Developer

Note that this is only buying you more time; eventually a new version of Xcode will be required for publishing anything to the App Store.

Razorholt commented 5 years ago

Thanks for your answer, @mernen but I'm not using Xcode. I was referring to Phonegap Build (PGB). Either way, I guess we'll have to wait...

mernen commented 5 years ago

@Razorholt Sorry, I'm indeed not familiar with PhoneGap Build; I thought it was similar to Cordova, in that it ran on a machine you owned? In that case, xcode-select should do the trick; if it's some kind of external build service, I guess you'll be entirely dependent on what options they offer you.

tehlothi commented 5 years ago

@mernen Thanks for the temporary solution, hopefully that works for me for my testing phase and the plugin is fixed before my next release date.

cmgustavo commented 5 years ago

I fixed the code to make it compatible with Swift 5, but the camera can't detect a QR code. Maybe I'm forgetting something before captureSession!.startRunning(). Of course, suggestions are welcome.

https://github.com/bitpay/cordova-plugin-qrscanner/pull/236

tehlothi commented 5 years ago

@cmgustavo I built using your code and I'm at the same state. My project successfully built (using Swift 4.2) but the QR scanner isn't able to successfully scan a code.

SilentKernel commented 5 years ago

Hi everyone.

captureOutput() has been removed from Swift, use metadataOutput() instead

Working example https://github.com/SilentKernel/cordova-plugin-qrscanner/blob/master/src/ios/QRScanner.swift

@cmgustavo

tehlothi commented 5 years ago

Hi everyone.

captureOutput() has been removed from Swift, use metadataOutput() instead

Working example https://github.com/SilentKernel/cordova-plugin-qrscanner/blob/master/src/ios/QRScanner.swift

@SilentKernel Just tested using this code on XCode 10.2 with Swift 4.2 and it's working just like it used to. Thank you so much.

cmgustavo commented 5 years ago

Thanks @SilentKernel !! That worked for me too.

Razorholt commented 5 years ago

That's great news! Thank you guys for contributing to that project. Please let me know when I can try the new version on Phonegap Build.

<plugin spec="https://github.com/SilentKernel/cordova-plugin-qrscanner.git" /> didn't work...

cmgustavo commented 5 years ago

Hi @Razorholt , try to modify directly the file in Xcode (src/ios/QRScanner.swift) and build again. Maybe you have to do cordova rm cordova-plugin-qrscanner and install again.

Or wait a bit until they upgrade the package in npmjs.com https://www.npmjs.com/package/cordova-plugin-qrscanner

Razorholt commented 5 years ago

I guess I'll wait till npmjs updates the package. Thanks @cmgustavo for all you do!

SilentKernel commented 5 years ago

@Razorholt it should work now you can add it with repo url

cmgustavo commented 5 years ago

The new version has been published: https://www.npmjs.com/package/cordova-plugin-qrscanner

I think that it 's not compatible with XCode 10.1. I'll take a look and let you know.

Razorholt commented 5 years ago

PhoneGap Build error:

Check dependencies
The “Swift Language Version” (SWIFT_VERSION) build setting must be set to a supported value
for targets which use Swift. Supported values are: 3.0, 4.0, 4.2. This setting can be set in 
the build settings editor.

Is there a Swift4 version available by any chance?

cmgustavo commented 5 years ago

Just updated plugin to v3.0.0 (not available yet on npm but master). It forces to use Swift 5 with:

<preference name="UseSwiftLanguageVersion" value="5" />

Also you can add it in your config.xml and re-build. But in v3 it won't be necessary.

Razorholt commented 5 years ago

Sorry, it didn't work. Same error msg: '... Supported values are: 3.0, 4.0, 4.2...'

cmgustavo commented 5 years ago

Lastest version (3.0.1) is available in https://www.npmjs.com/package/cordova-plugin-qrscanner

Since the plugin depends of cordova-plugin-add-swift-support and it has Swift 3 as default. You should add this to your config.xml

<preference name="UseSwiftLanguageVersion" value="5" />

For old Xcode (<= 10.1). Use cordova-plugin-qrscanner 2.6.2.

Thanks!

baotpham commented 5 years ago

Version 3.0.1 works perfectly fine. Thank you!

Will updating cordova-plugin-add-swift-support allow us to set this?

<preference name="UseSwiftLanguageVersion" value="5" />

The version for swift support is now 2.0.2. It supports swift 4.0 by default

SandroMoretti commented 5 years ago

@baotpham

https://github.com/akofman/cordova-plugin-add-swift-support

In github plugin page tell that is possible set swift language version to 5.

SandroMoretti commented 5 years ago

I really can't build when using cordova-plugin-qrscanner@3.0.1

I'm using add-swift-support version 5, and x-code version 10.2.1 (in x-code, swift 5 is selected). My platform is ios@5.0.1

When I try build I get the follow errors:

The following build commands failed:
     PrecompileSwiftBridgingHeader normal armv7
     CompileSwiftSources normal armv7 com.apple.xcode.tools.swift.compiler
     PrecompileSwiftBridgingHeader normal arm64

If I remove qrscanner plugin works perfectly (using swift 5 too). Please help?

b1ueRa1n commented 4 years ago

This Example working for me.

Hi everyone. captureOutput() has been removed from Swift, use metadataOutput() instead Working example https://github.com/SilentKernel/cordova-plugin-qrscanner/blob/master/src/ios/QRScanner.swift

@SilentKernel Just tested using this code on XCode 10.2 with Swift 4.2 and it's working just like it used to. Thank you so much.

This Example working for me. But need change "string: UIApplication.openSettingsURLString" to "string: UIApplicationOpenSettingsURLString" in openSettings function. line 470