{"id":13694539,"url":"https://github.com/heart/CarBode-Barcode-Scanner-For-SwiftUI","last_synced_at":"2025-05-03T04:30:38.080Z","repository":{"id":35843007,"uuid":"213380392","full_name":"heart/CarBode-Barcode-Scanner-For-SwiftUI","owner":"heart","description":"CarBode : Free \u0026 Opensource barcode scanner \u0026 generator for SwiftUI","archived":false,"fork":false,"pushed_at":"2024-11-01T08:51:19.000Z","size":27670,"stargazers_count":294,"open_issues_count":16,"forks_count":52,"subscribers_count":11,"default_branch":"master","last_synced_at":"2025-04-07T09:15:01.136Z","etag":null,"topics":["barcode-generator","barcode-scanner","carbode-barcode-scanner","ios-app","opensource-barcode-scanner","qrcode","swiftui","swiftui-components"],"latest_commit_sha":null,"homepage":"","language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/heart.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-10-07T12:43:07.000Z","updated_at":"2025-03-09T10:51:14.000Z","dependencies_parsed_at":"2024-11-12T21:42:50.421Z","dependency_job_id":null,"html_url":"https://github.com/heart/CarBode-Barcode-Scanner-For-SwiftUI","commit_stats":null,"previous_names":[],"tags_count":18,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/heart%2FCarBode-Barcode-Scanner-For-SwiftUI","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/heart%2FCarBode-Barcode-Scanner-For-SwiftUI/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/heart%2FCarBode-Barcode-Scanner-For-SwiftUI/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/heart%2FCarBode-Barcode-Scanner-For-SwiftUI/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/heart","download_url":"https://codeload.github.com/heart/CarBode-Barcode-Scanner-For-SwiftUI/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252144277,"owners_count":21701380,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["barcode-generator","barcode-scanner","carbode-barcode-scanner","ios-app","opensource-barcode-scanner","qrcode","swiftui","swiftui-components"],"created_at":"2024-08-02T17:01:34.394Z","updated_at":"2025-05-03T04:30:33.068Z","avatar_url":"https://github.com/heart.png","language":"Swift","funding_links":[],"categories":["Misc","QRCode","🛠 Examples"],"sub_categories":["SwiftUI","Content","Open Source Apps"],"readme":"![CarBode](https://raw.githubusercontent.com/heart/CarBode-Barcode-Scanner-For-SwiftUI/master/logo/logo.png)\n\n\"The name CarBode is a playful twist on the word Barcode. It’s a Thai wordplay technique, where syllables are reversed to create a new, catchy name. This adds a touch of humor and a unique Thai flair that makes the project memorable.\"\n\n---\n\n# CarBode\n\n## Free and Opensource Barcode scanner \u0026amp; Barcode generator for swiftUI\n\n![CarBodeDemo](https://raw.githubusercontent.com/heart/CarBode-Barcode-Scanner-For-SwiftUI/master/logo/demo.gif)\n\n# Why you must use CarBode\n\n1. CarBode have both Barcode Scanner and Barcode Generator\n1. CarBode is a lightweight components\n1. CarBode build on AVFoundation it will supported all of barcodes types that AVFoundation supported\n1. CarBode can turn on the torch light and it can toggle between front and back camera\n\n![Supported Barcode](https://raw.githubusercontent.com/heart/CarBode-Barcode-Scanner-For-SwiftUI/master/logo/barcode_type.jpg)\n\n## index\n\n- [Installation](#installation)\n- [Example project](#example-project)\n- [How to use scanner view](#how-to-use-scanner-view)\n  - [Add camera usage description to `info.plist`](#add-camera-usage-description-to-your-infoplist)\n  - [Simple Scanner](#simple-scanner)\n  - [Draw box around the barcode](#draw-box-around-the-barcode)\n  - [torch light on/off](#how-to-turn-torch-light-onoff)\n  - [Switch front/back camera](#switch-to-front-camera)\n  - [Barcode types support](#barcode-types-support)\n  - [Test on iOS simulator](#test-on-ios-simulator)\n- [How to use barcode generator view](#how-to-use-barcode-generator-view)\n  - [Barcode type you can generate](#barcode-type-you-can-generate)\n  - [Rotate your barcode](#rotate-your-barcode)\n- [How to contributing](#contributing)\n- [Version Change logs](#changelog)\n\n# Installation\n\nThe preferred way of installing SwiftUIX is via the [Swift Package Manager](https://swift.org/package-manager/).\n\n\u003e Xcode 11 integrates with libSwiftPM to provide support for iOS, watchOS, and tvOS platforms.\n\n1. In Xcode, open your project and navigate to **File** → **Swift Packages** → **Add Package Dependency...**\n2. Paste the repository URL (`https://github.com/heart/CarBode-Barcode-Scanner-For-SwiftUI`) and click **Next**.\n3. For **Rules**, select **Branch** (with branch set to `2.1.2` ).\n4. Click **Finish**.\n\n# Example project\n\nCarBode-Barcode-Scanner-For-SwiftUI/ExampleProject/ExampleProject.xcodeproj\n\n![Carbode Example project](https://raw.githubusercontent.com/heart/CarBode-Barcode-Scanner-For-SwiftUI/master/logo/example_project.png)\n\n# How to use Scanner View\n\n![SwiftUI QRCode Scanner](https://raw.githubusercontent.com/heart/CarBode-Barcode-Scanner-For-SwiftUI/master/logo/scan.png)\n\n## Add camera usage description to your `info.plist`\n\n```XML\n\u003ckey\u003eNSCameraUsageDescription\u003c/key\u003e\n\u003cstring\u003eThis app needs access to the camera, to be able to read barcodes.\u003c/string\u003e\n```\n\n# Simple Scanner\n\n```Swift\nimport SwiftUI\nimport CarBode\nimport AVFoundation //import to access barcode types you want to scan\n\nstruct ContentView: View {\n\n    var body: some View {\n        VStack{\n\n        CBScanner(\n                supportBarcode: .constant([.qr, .code128]), //Set type of barcode you want to scan\n                scanInterval: .constant(5.0) //Event will trigger every 5 seconds\n            ){\n                //When the scanner found a barcode\n                print(\"BarCodeType =\",$0.type.rawValue, \"Value =\",$0.value)\n            }\n\n    }\n}\n```\n\n# Draw box around the barcode\n\n```Swift\nimport SwiftUI\nimport CarBode\nimport AVFoundation //import to access barcode types you want to scan\n\nstruct ContentView: View {\n    var body: some View {\n        VStack{\n        CBScanner(\n                supportBarcode: .constant([.qr, .code128]), //Set type of barcode you want to scan\n                scanInterval: .constant(5.0) //Event will trigger every 5 seconds\n            ){\n                //When the scanner found a barcode\n                print(\"BarCodeType =\",$0.type.rawValue, \"Value =\",$0.value)\n            }\n            onDraw: {\n                print(\"Preview View Size = \\($0.cameraPreviewView.bounds)\")\n                print(\"Barcode Corners = \\($0.corners)\")\n\n                //line width\n                let lineWidth = 2\n\n                //line color\n                let lineColor = UIColor.red\n\n                //Fill color with opacity\n                //You also can use UIColor.clear if you don't want to draw fill color\n                let fillColor = UIColor(red: 0, green: 1, blue: 0.2, alpha: 0.4)\n\n                //Draw box\n                $0.draw(lineWidth: lineWidth, lineColor: lineColor, fillColor: fillColor)\n            }\n    }\n}\n```\n\n# How to turn torch light on/off\n\n```Swift\nimport SwiftUI\nimport CarBode\nimport AVFoundation //import to access barcode types you want to scan\n\n@State var torchIsOn = false\n\nstruct ContentView: View {\n    var body: some View {\n        VStack{\n\n        Button(action: {\n            self.torchIsOn.toggle() //Toggle On/Off\n        }) {\n            Text(\"Toggle Torch Light\")\n        }\n\n        Spacer()\n\n        CBScanner(\n                supportBarcode: .constant([.qr, .code128]), //Set type of barcode you want to scan\n                scanInterval: .constant(5.0), //Event will trigger every 5 seconds\n                torchLightIsOn: $torchIsOn // Bind a Bool to enable/disable torch light\n            ){\n                //When the scanner found a barcode\n                print(\"BarCodeType =\",$0.type.rawValue, \"Value =\",$0.value)\n            }\n        }\n    }\n}\n```\n\n# Switch to front camera\n\n```swift\nimport SwiftUI\nimport CarBode\nimport AVFoundation //import to access barcode types you want to scan\n\n@State var torchIsOn = false\n\nstruct ContentView: View {\n    var body: some View {\n        VStack{\n\n        @State var cameraPosition = AVCaptureDevice.Position.back\n\n        // Click to Toggle camera\n        Button(action: {\n            if cameraPosition == .back {\n                cameraPosition = .front\n            }else{\n                cameraPosition = .back\n            }\n        }) {\n            if cameraPosition == .back{\n                Text(\"Swicth Camera to Front\")\n            }else{\n                Text(\"Swicth Camera to Back\")\n            }\n        }\n\n        Spacer()\n\n        CBScanner(\n                supportBarcode: .constant([.qr, .code128]), //Set type of barcode you want to scan\n                scanInterval: .constant(5.0), //Event will trigger every 5 seconds\n\n                cameraPosition: $cameraPosition  //Bind to switch front/back camera\n            ){\n                //When the scanner found a barcode\n                print(\"BarCodeType =\",$0.type.rawValue, \"Value =\",$0.value)\n            }\n        }\n    }\n}\n\n```\n\n# Test on iOS simulator\n\nThe iOS simulator doesn't support the camera yet\nbut you can set a mock barcode for iOS simulator.\n\nNo need to remove the mock barcode from the production app it will only use for iOS simulator.\n\n```Swift\n    CBScanner(\n        supportBarcode: .constant([.qr, .code128]), //Set type of barcode you want to scan\n        scanInterval: .constant(5.0), //Event will trigger every 5 seconds\n        mockBarCode: .constant(BarcodeData(value:\"Mocking data\", type: .qr))\n    ){\n        //When you click the button on screen mock data will appear here\n        print(\"BarCodeType =\",$0.type.rawValue, \"Value =\",$0.value)\n    }\n```\n\n## Barcode Types Support\n\nRead here [https://developer.apple.com/documentation/avfoundation/avmetadataobject/objecttype](https://developer.apple.com/documentation/avfoundation/avmetadataobject/objecttype)\n\n# How to use barcode generator view\n\n![SwiftUI QRCode Scanner](https://raw.githubusercontent.com/heart/CarBode-Barcode-Scanner-For-SwiftUI/master/logo/generator.png)\n\n## Example code\n\n```Swift\nimport SwiftUI\n\nstruct ModalBarcodeGenerator: View {\n    @State var dataString = \"Hello Carbode\"\n    @State var barcodeType = CBBarcodeView.BarcodeType.qrCode\n    @State var rotate = CBBarcodeView.Orientation.up\n\n    var body: some View {\n        var body: some View {\n            VStack {\n                CBBarcodeView(data: $dataString,\n                              barcodeType: $barcodeType,\n                              orientation: $rotate)\n                    .frame(minWidth: 0, maxWidth: .infinity, minHeight: 400, maxHeight: 400, alignment: .topLeading)\n            }\n        }\n    }\n}\n```\n\n# Barcode type you can generate\n\n```Swift\n//QR Code\n// CBBarcodeView.BarcodeType.qrCode\n//Code 128\n// CBBarcodeView.BarcodeType.barcode128\n//Aztec Code\n// CBBarcodeView.BarcodeType.aztecCode\n//PDF417\n// CBBarcodeView.BarcodeType.PDF417\n\n@State var barcodeType = CBBarcodeView.BarcodeType.qrCode\nCBBarcodeView(data: ..... ,\n                barcodeType: $barcodeType ,\n                orientation: ... )\n```\n\n# Rotate your barcode\n\n```Swift\n/*Youcan rotate 4 directions\nCBBarcodeView.Orientation.up\nCBBarcodeView.Orientation.down\nCBBarcodeView.Orientation.left\nCBBarcodeView.Orientation.right*/\n\n@State var rotate = CBBarcodeView.Orientation.left\nCBBarcodeView(data: ..... ,\n                barcodeType: ..... ,\n                orientation: $rotate)\n```\n\n# Contributing\n\nCarBode welcomes contributions in the form of GitHub issues and pull-requests.\n\n## Changelog\n\n    - 2.1.2 When scan on difference barcode scanner will ignore the delay time\n    - 2.1.1 Fixed bugs\n    - 2.1.0 You can draw a box around the barcode\n    - 2.0.1 Fixed bugs\n    - 2.0.0 I learned many more things about SwiftUI then I decide to restructure the scanner I hope you will like it. And this version you can switch front and back camera.\n    - 1.5.0 Fixed bugs and you can read the barcode type when scanner found it\n    - 1.4.0 Rename component and add new barcode generator view component\n    - 1.3.0 You can set a mock barcode when running with an iOS simulator.\n    - 1.2.0 Add feature allows to turn torch light on or off.\n    - 1.0.1 Fixed bug camera delay 10 seconds when use on modal.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fheart%2FCarBode-Barcode-Scanner-For-SwiftUI","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fheart%2FCarBode-Barcode-Scanner-For-SwiftUI","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fheart%2FCarBode-Barcode-Scanner-For-SwiftUI/lists"}