Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/masashi-sutou/codescanner
CodeScanner is easy to scan a barcode or QR code.
https://github.com/masashi-sutou/codescanner
barcode camera qr-code scanner
Last synced: about 1 month ago
JSON representation
CodeScanner is easy to scan a barcode or QR code.
- Host: GitHub
- URL: https://github.com/masashi-sutou/codescanner
- Owner: masashi-sutou
- License: mit
- Created: 2017-02-18T10:06:56.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2017-09-21T17:35:02.000Z (over 7 years ago)
- Last Synced: 2024-09-24T13:04:37.261Z (3 months ago)
- Topics: barcode, camera, qr-code, scanner
- Language: Swift
- Homepage:
- Size: 41 KB
- Stars: 1
- Watchers: 2
- Forks: 5
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
CodeScanner
====## Overview
- Generate code
- QR
- Code128Barcode
- Detect photo
- QR
- Detect by camera
- QR
- Code128Barcode## Requirement
- Xcode 8 or later
- Swift 3 or later
- iOS 8.0 or later## Usage
#### Generate code
- QR
```Swift
self.imageView.image = Code.generateQRCode(text: "message")
```- Code128Barcode
```Swift
self.imageView.image = Code.generate128Barcode(text: "message")
```#### Detect photo
- QR
```Swift
// MARK: UINavigationControllerDelegate, UIImagePickerControllerDelegatefunc imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
if let selectedImage = info[UIImagePickerControllerOriginalImage] as? UIImage {
let messages: [String] = Code.detectQRCodes(image: selectedImage)
if messages.count > 0 {
self.textView.text = messages.first
} else {
self.textView.text = "[Not Found QR Code in Photo]"
}
}dismiss(animated: true, completion: nil)
}
```#### Detect by camera
- QR
```Swift
import UIKit
import AVFoundation
import CodeScannerfinal class QRCodeDetectForCameraViewController: UIViewController {
private var scanner: CodeScanner!
override func viewDidLoad() {
super.viewDidLoad()
self.navigationItem.title = "Detect QR code from Camera"
self.view.backgroundColor = .groupTableViewBackgroundself.scanner = CodeScanner(metadataObjectTypes: [AVMetadataObjectTypeQRCode], preview: self.view)
}override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)CodeScanner.requestCameraPermission { (success) in
if success {
self.scanner.scan(resultOutputs: { (outputs) in
print(outputs)
})
}
}
}
}
```- Code128Barcode
```Swift
import UIKit
import AVFoundation
import CodeScannerfinal class BarcodeDetectForCameraViewController: UIViewController {
private var scanner: CodeScanner!
override func viewDidLoad() {
super.viewDidLoad()
self.navigationItem.title = "Detect Barcode from Camera"
self.view.backgroundColor = .groupTableViewBackgroundself.scanner = CodeScanner(metadataObjectTypes: [AVMetadataObjectTypeEAN8Code, AVMetadataObjectTypeEAN13Code, AVMetadataObjectTypeCode128Code], preview: self.view)
}override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)CodeScanner.requestCameraPermission { (success) in
if success {
self.scanner.scan(resultOutputs: { (outputs) inif let output: String = outputs.first {
if output.isJANLowerBarcode() {
return
}if let isbn = output.convartISBN() {
self.scanner.stop()
isbn.searchAamazon()
}
}
})
}
}
}
}
```## Installation
#### [CocoaPods](https://cocoapods.org/)
Add the following line to your Podfile:
```ruby
use_frameworks!target 'YOUR_TARGET_NAME' do
pod "CodeScanner"
end
```#### [Carthage](https://github.com/Carthage/Carthage)
Add the following line to your Cartfile:
```ruby
github "masashi-sutou/CodeScanner"
```## Licence
CodeScanner is available under the MIT license. See the LICENSE file for more info.