Last active
March 22, 2020 00:40
-
-
Save quindariuss/ab047d1410fa9e35f2221a101da3b374 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import CodeScanner | |
import SwiftUI | |
struct CodeScanner: View { | |
@State private var isShowingScanner = false | |
var body: some View { | |
Button(action: { | |
self.isShowingScanner = true | |
}) { | |
Text("Show Scanner") | |
} | |
.sheet(isPresented: $isShowingScanner) { | |
CodeScannerView(codeTypes: [.qr], simulatedData: "Some simulated data", completion: self.handleScan) | |
} | |
} | |
func handleScan(result: Result<String, CodeScannerView.ScanError>) { | |
self.isShowingScanner = false | |
switch result { | |
case .success(let data): | |
print("Success with \(data)") | |
case .failure(let error): | |
print("Scanning failed \(error)") | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment