WBQRCodeSanner is QR Code Scanner in SwiftUI
-
iOS 13.0+
-
Xcode 11.0+
Using Xcode 11, go to File -> Swift Packages -> Add Package Dependency
and enter https://github.com/WBearJ/WBQRCodeScanner.git
info.plist
<key>NSCameraUsageDescription</key>
<string>app needs access to the camera to scan the qr code</string>
That's a basic example. use the default camera preview
import SwiftUI
import WBQRCodeScanner
struct ContentView: View {
@State var results = [WBQRBarcodeResult]()
var body: some View {
NavigationStack {
NavigationLink {
WBQRScanner { results in
self.results = results
}
} label: {
Text("Default Scan Preview")
}
// scan value
if !results.isEmpty {
// title
Text("Scan Result")
.font(.title3)
.padding(.top, 10)
// results
ForEach(results, id: \.stringValue) { result in
Text("Result: \(result.stringValue ?? "")")
}
}
}
}
}
If you want customize the preview, you just modify the WBQRScanPreview
, here is the simple explore:
func scannerView() -> some View {
WBQRScanner {
// customize preview
Text("you can customize preview here")
} scanResults: { results in
// do something with the results
}
}
- 0.0.1 - Basic functions
- 0.0.2 - Improve usages, add photo album recognize function
This project is licensed under the MIT License - see the LICENSE file for details