TEAM LICENSES: Save money and learn new skills through a Hacking with Swift+ team license >>

Barcode Scanner continuous scanning?

Forums > SwiftUI

I followed the steps to get a barcode scanner set up in the app from here: https://www.hackingwithswift.com/books/ios-swiftui/scanning-qr-codes-with-swiftui

I am hoping I could have a toggle switch to enable continuous scanning, so that I didn't have to press the button every time. I have the toggle set up to a boolean variable but not sure where to go from there. I've tried setting "self.isShowingScanner" to false and back to true depending on if the toggle is enabled or not and have had no luck.

Thanks in advance for any advice!

2      

IDK, Maybe you shuld use UserDefaults

2      

I figured it out, you can specify the scanmode when calling the CodeScannerView. You also have to take out the self.isShowingScanner = false in the handleScan function. Alternativley, like I did you could have a variable that is toggle with a toggle switch and if the toggle is true then self.isShowingScanner = false which would cause it to only scan once!

Here is my exampe of the CodeScannerView call if anyone is wanting to do the same thing.

CodeScannerView(codeTypes: [.code39],scanMode: .continuous,scanInterval: 1, simulatedData: "blahblah", completion: self.handleScan)

2      

Hacking with Swift is sponsored by Blaze.

SPONSORED Still waiting on your CI build? Speed it up ~3x with Blaze - change one line, pay less, keep your existing GitHub workflows. First 25 HWS readers to use code HACKING at checkout get 50% off the first year. Try it now for free!

Reserve your spot now

Sponsor Hacking with Swift and reach the world's largest Swift community!

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.