Giter Site home page Giter Site logo

justluffy / carbode-barcode-scanner-for-swiftui Goto Github PK

View Code? Open in Web Editor NEW

This project forked from rajubd49/carbode-barcode-scanner-for-swiftui

0.0 0.0 0.0 8.04 MB

CarBode : Free & Opensource barcode scanner & generator for SwiftUI

License: MIT License

Swift 100.00%

carbode-barcode-scanner-for-swiftui's Introduction

CarBode

CarBode

Free and Opensource Barcode scanner & Barcode generator for swiftUI

Supported Barcode

index

Installation

The preferred way of installing SwiftUIX is via the Swift Package Manager.

Xcode 11 integrates with libSwiftPM to provide support for iOS, watchOS, and tvOS platforms.

  1. In Xcode, open your project and navigate to File โ†’ Swift Packages โ†’ Add Package Dependency...
  2. Paste the repository URL (https://github.com/heart/CarBode-Barcode-Scanner-For-SwiftUI) and click Next.
  3. For Rules, select Branch (with branch set to 1.4.2 ).
  4. Click Finish.

Example project

CarBode-Barcode-Scanner-For-SwiftUI/ExampleProject/ExampleProject.xcodeproj

Carbode Example project

How to use Scanner View

SwiftUI QRCode Scanner

Add camera usage description to your info.plist

<key>NSCameraUsageDescription</key>
<string>This app needs access to the camera, to be able to read barcodes.</string>
import SwiftUI
import CarBode

struct ContentView: View {
    var body: some View {
        VStack{
        CBScanner(supportBarcode: [.qr, .code128]) //Set type of barcode you want to scan
                    .interval(delay: 5.0) //Event will trigger every 5 seconds
                       .found{
                            //Your..Code..Here
                            print($0)
                      }
        }
    }
}

How to turn torch light on/off

import SwiftUI
import CarBode

@State var torceIsOn = false

struct ContentView: View {
    var body: some View {
        VStack{

        Button(action: {
            self.torceIsOn.toggle()
        }) {
            Text("Toggle Torch Light")
        }
            
        Spacer()
        
        CBScanner(supportBarcode: [.qr, .code128]) //Set type of barcode you want to scan
                    .torchLight(isOn: self.torceIsOn) // Turn torch light on/off
                    .interval(delay: 5.0) //Event will trigger every 5 seconds
                       .found{
                            //Your..Code..Here
                            print($0)
                      }
        }
    }
}

Test on iOS simulator

The iOS simulator doesn't support the camera yet but you can set a mock barcode for iOS simulator.

No need to remove the mock barcode it will only use for iOS simulator.

 CBScanner(supportBarcode: [.qr, .code128])
            .interval(delay: 1.0)
            .found{
                print($0)
            }
            .simulator(mockBarCode: "MOCK BARCODE DATA 1234567890")

Barcode Types Support

Read here https://developer.apple.com/documentation/avfoundation/avmetadataobject/objecttype

How to use barcode generator view

SwiftUI QRCode Scanner

Excample code

import SwiftUI

struct ModalBarcodeGenerator: View {
    @State var dataString = "Hello Carbode"
    @State var barcodeType = CBBarcodeView.BarcodeType.qrCode
    @State var rotate = CBBarcodeView.Orientation.up

    var body: some View {
        var body: some View {
        VStack {
            CBBarcodeView(data: $dataString,
                barcodeType: $barcodeType,
                orientation: $rotate)
                .frame(minWidth: 0, maxWidth: .infinity, minHeight: 400, maxHeight: 400, alignment: .topLeading)
        }
    }
}

Barcode type you can generate

//QR Code
// CBBarcodeView.BarcodeType.qrCode
//Code 128
// CBBarcodeView.BarcodeType.barcode128
//Aztec Code
// CBBarcodeView.BarcodeType.aztecCode
//PDF417
// CBBarcodeView.BarcodeType.PDF417

@State var barcodeType = CBBarcodeView.BarcodeType.qrCode
CBBarcodeView(data: ..... ,
                barcodeType: $barcodeType ,
                orientation: ... )

Rotate your barcode

/*Youcan rotate 4 directions
CBBarcodeView.Orientation.up
CBBarcodeView.Orientation.down
CBBarcodeView.Orientation.left
CBBarcodeView.Orientation.right*/

@State var rotate = CBBarcodeView.Orientation.left
CBBarcodeView(data: ..... ,
                barcodeType: ..... ,
                orientation: $rotate)

Contributing

CarBode welcomes contributions in the form of GitHub issues and pull-requests.

Changelog

- 1.0.1 Fixed bug camera delay 10 seconds when use on modal.
- 1.2.0 Add feature allows to turn torch light on or off.
- 1.3.0 You can set a mock barcode when running with an iOS simulator.
- 1.4.0 Rename component and add new barcode generator view component

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.