UPGRADE YOUR SKILLS: Learn advanced Swift and SwiftUI on Hacking with Swift+! >>

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      

TAKE YOUR SKILLS TO THE NEXT LEVEL If you like Hacking with Swift, you'll love Hacking with Swift+ – it's my premium service where you can learn advanced Swift and SwiftUI, functional programming, algorithms, and more. Plus it comes with stacks of benefits, including monthly live streams, downloadable projects, a 20% discount on all books, and free gifts!

Find out more

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.