Skip to content

WBearJ/WBQRCodeScanner

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

WBQRCodeScanner

Platforms License: MIT

WBQRCodeSanner is QR Code Scanner in SwiftUI

Requirements

  • iOS 13.0+

  • Xcode 11.0+

Installation

Swift Package Manager

Using Xcode 11, go to File -> Swift Packages -> Add Package Dependency and enter https://github.com/WBearJ/WBQRCodeScanner.git

Usage

⚠️ Before use, add camera usage description to your 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
  }
}

Release Note

  • 0.0.1 - Basic functions
  • 0.0.2 - Improve usages, add photo album recognize function

License

This project is licensed under the MIT License - see the LICENSE file for details