{"id":13743119,"url":"https://github.com/mikebuss/MTBBarcodeScanner","last_synced_at":"2025-05-09T00:32:50.391Z","repository":{"id":13959201,"uuid":"16659503","full_name":"mikebuss/MTBBarcodeScanner","owner":"mikebuss","description":"A lightweight, easy-to-use barcode scanning library for iOS 8+","archived":true,"fork":false,"pushed_at":"2020-10-01T00:31:34.000Z","size":4416,"stargazers_count":1088,"open_issues_count":3,"forks_count":198,"subscribers_count":38,"default_branch":"develop","last_synced_at":"2024-05-17T06:01:29.085Z","etag":null,"topics":["barcode-scanning","camera","carthage","cocoapods","objective-c","swift"],"latest_commit_sha":null,"homepage":"","language":"Objective-C","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/mikebuss.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-02-09T04:06:33.000Z","updated_at":"2024-05-10T10:31:32.000Z","dependencies_parsed_at":"2022-08-02T15:46:03.066Z","dependency_job_id":null,"html_url":"https://github.com/mikebuss/MTBBarcodeScanner","commit_stats":null,"previous_names":[],"tags_count":56,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mikebuss%2FMTBBarcodeScanner","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mikebuss%2FMTBBarcodeScanner/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mikebuss%2FMTBBarcodeScanner/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mikebuss%2FMTBBarcodeScanner/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mikebuss","download_url":"https://codeload.github.com/mikebuss/MTBBarcodeScanner/tar.gz/refs/heads/develop","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224604862,"owners_count":17339221,"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-scanning","camera","carthage","cocoapods","objective-c","swift"],"created_at":"2024-08-03T05:00:40.959Z","updated_at":"2024-11-15T14:30:55.861Z","avatar_url":"https://github.com/mikebuss.png","language":"Objective-C","readme":"# This library is no longer actively maintained. If you are interested in maintaining it, please contact [the original author](mailto:mike@mikebuss.com).\n\n# MTBBarcodeScanner\n\n[![Version](https://img.shields.io/cocoapods/v/MTBBarcodeScanner.svg?style=flat)](http://cocoadocs.org/docsets/MTBBarcodeScanner)\n[![License](https://img.shields.io/cocoapods/l/MTBBarcodeScanner.svg?style=flat)](http://cocoadocs.org/docsets/MTBBarcodeScanner)\n[![Platform](https://img.shields.io/cocoapods/p/MTBBarcodeScanner.svg?style=flat)](http://cocoadocs.org/docsets/MTBBarcodeScanner)\n[![Carthage Compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage)\n\nA lightweight, easy-to-use barcode scanning library for iOS 8+. This library is built on top of Apple's excellent AVFoundation framework, and will continue to receive updates as Apple releases them.\n\nWith this library you can:\n\n- Supply a custom UIView for displaying camera input\n- Read any number of barcodes before stopping\n- Read multiple codes on the screen at the same time (2D barcodes only)\n- Easily read codes with a block, including the string value and position in the preview\n- Easily flip from the back to the front camera\n- Toggle the device's torch on and off\n- Freeze and unfreeze capture to display a still image from the camera\n\nSee demo project for examples of capturing one code, multiple codes, or highlighting codes as valid or invalid in the live preview.\n\n---\n\n\u003cimg src=\"https://raw.githubusercontent.com/mikebuss/MTBBarcodeScanner/develop/Assets/MTBBarcodeScanner.png\" width=100% height=100%\u003e\n\n#### Sample Barcodes\n\n\u003cimg src=\"https://raw.githubusercontent.com/mikebuss/MTBBarcodeScanner/develop/Assets/sample-barcodes.png\" width=50% height=50%\u003e\n\n---\n\n## Installation\n\n### CocoaPods\n\nMTBBarcodeScanner can be installed via [CocoaPods](http://cocoapods.org) by adding the following line to your Podfile:\n\n`pod \"MTBBarcodeScanner\"`\n\n### Carthage\n\n[Carthage](https://github.com/Carthage/Carthage) is a decentralized dependency manager that builds your dependencies and provides you with binary frameworks.\n\nYou can install Carthage with [Homebrew](http://brew.sh/) using the following command:\n\n```bash\n$ brew update\n$ brew install carthage\n```\n\nTo integrate MTBBarcodeScanner into your Xcode project using Carthage, specify it in your `Cartfile`:\n\n```ogdl\ngithub \"mikebuss/MTBBarcodeScanner\"\n```\n\nRun `carthage update` to build the framework and drag the built `MTBBarcodeScanner.framework` into your Xcode project.\n\n### Manual\n\n\nIf you'd prefer not to use a dependency manager, you can download [these two files](https://github.com/mikebuss/MTBBarcodeScanner/tree/master/Classes/ios/Scanners) and add them to your project:\n\n[`MTBBarcodeScanner.h`](https://github.com/mikebuss/MTBBarcodeScanner/blob/master/Classes/ios/Scanners/MTBBarcodeScanner.h)\n\n[`MTBBarcodeScanner.m`](https://github.com/mikebuss/MTBBarcodeScanner/blob/master/Classes/ios/Scanners/MTBBarcodeScanner.m)\n\n---\n\n## Usage in Objective-C Projects\n\nTo import the library: `#import \"MTBBarcodeScanner.h\"`\n\n#### Initialization\n\nTo initialize an instance of `MTBBarcodeScanner`:\n\n```objective-c\nscanner = [[MTBBarcodeScanner alloc] initWithPreviewView:self.previewView];\n```\n\nWhere `previewView` is the `UIView` in which the camera input will be displayed.\n\nIf you only want to scan for certain MetaObjectTypes, you can initialize with the `initWithMetadataObjectTypes:previewView:` method:\n\n```objective-c\ns = [[MTBBarcodeScanner alloc] initWithMetadataObjectTypes:@[AVMetadataObjectTypeQRCode]\n                                               previewView:self.previewView];\n```\n\n#### iOS 10 and later\n\nIf you are using the `MTBBarcodeScanner` library on iOS 10 and later, you need to include the following `Info.plist` key in order to request camera access or the application will crash:\n```xml\n\u003ckey\u003eNSCameraUsageDescription\u003c/key\u003e\n\u003cstring\u003eCan we access your camera in order to scan barcodes?\u003c/string\u003e\n```\nOf course you can also set your own (localized) message here. To find out more about privacy-keys in iOS, check the \n[official Apple documentation](https://developer.apple.com/library/content/documentation/General/Reference/InfoPlistKeyReference/Articles/CocoaKeys.html).\n\n#### Scanning\n\nTo read the first code and stop scanning:\n\n**Note:** To avoid a delay in the camera feed, start scanning in `viewDidAppear` and not `viewDidLoad`.\n\n```objective-c\n[MTBBarcodeScanner requestCameraPermissionWithSuccess:^(BOOL success) {\n    if (success) {\n\n        NSError *error = nil;\n        [self.scanner startScanningWithResultBlock:^(NSArray *codes) {\n            AVMetadataMachineReadableCodeObject *code = [codes firstObject];\n            NSLog(@\"Found code: %@\", code.stringValue);\n\n            [self.scanner stopScanning];\n        } error:\u0026error];\n\n    } else {\n        // The user denied access to the camera\n    }\n}];\n```\n\nIf the camera is pointed at more than one 2-dimensional code, you can read all of them:\n\n```objective-c\nNSError *error = nil;\n[self.scanner startScanningWithResultBlock:^(NSArray *codes) {\n    for (AVMetadataMachineReadableCodeObject *code in codes) {\n        NSLog(@\"Found code: %@\", code.stringValue);\n    }\n    [self.scanner stopScanning];\n} error:\u0026error];\n```\n\n**Note:** This only applies to 2-dimensional barcodes as 1-dimensional barcodes can only be read one at a time. See [relevant Apple document](https://developer.apple.com/library/ios/technotes/tn2325/_index.html).\n\nTo continuously read and only output unique codes:\n\n```objective-c\nNSError *error = nil;\n[self.scanner startScanningWithResultBlock:^(NSArray *codes) {\n    for (AVMetadataMachineReadableCodeObject *code in codes) {\n        if ([self.uniqueCodes indexOfObject:code.stringValue] == NSNotFound) {\n            [self.uniqueCodes addObject:code.stringValue];\n            NSLog(@\"Found unique code: %@\", code.stringValue);\n        }\n    }\n} error:\u0026error];\n```\n\n#### Callback Blocks\n\nAn alternative way to setup MTBBarcodeScanner is to configure the blocks directly, like so:\n\n```objective-c\nself.scanner.didStartScanningBlock = ^{\n    NSLog(@\"The scanner started scanning! We can now hide any activity spinners.\");\n};\n\nself.scanner.resultBlock = ^(NSArray *codes){\n    NSLog(@\"Found these codes: %@\", codes);\n};\n\nself.scanner.didTapToFocusBlock = ^(CGPoint point){\n    NSLog(@\"The user tapped the screen to focus. \\\n          Here we could present a view at %@\", NSStringFromCGPoint(point));\n};\n\n[self.scanner startScanning];\n```\n\nThis is useful if you would like to present a spinner while MTBBarcodeScanner is initializing.\n\nIf you would like to reference `self` in one of these blocks, remember to use a weak reference to avoid a retain cycle:\n\n```objective-c\n__weak MyViewController *weakSelf = self;\nself.scanner.resultBlock = ^(NSArray *codes){\n    [weakSelf drawOverlaysOnCodes:codes];\n};\n```\n---\n\n## Usage in Swift 3+ Projects\n\nSee the `SwiftExampleViewController.swift` file in the repository for a working example of this.\n\n```swift\nimport UIKit\nimport MTBBarcodeScanner\n\nclass SwiftExampleViewController: UIViewController {\n    \n    @IBOutlet var previewView: UIView!\n    var scanner: MTBBarcodeScanner?\n    \n    override func viewDidLoad() {\n        super.viewDidLoad()\n        \n        scanner = MTBBarcodeScanner(previewView: previewView)\n\n        // Alternatively, limit the type of codes you can scan:\n        // scanner = MTBBarcodeScanner(metadataObjectTypes: [AVMetadataObject.ObjectType.qr.rawValue], previewView: previewView)\n    }\n    \n    override func viewDidAppear(_ animated: Bool) {\n        super.viewDidAppear(animated)\n        \n        MTBBarcodeScanner.requestCameraPermission(success: { success in\n            if success {\n                do {\n                    try self.scanner?.startScanning(resultBlock: { codes in\n                        if let codes = codes {\n                            for code in codes {\n                                let stringValue = code.stringValue!\n                                print(\"Found code: \\(stringValue)\")\n                            }\n                        }\n                    })\n                } catch {\n                    NSLog(\"Unable to start scanning\")\n                }\n            } else {\n                UIAlertView(title: \"Scanning Unavailable\", message: \"This app does not have permission to access the camera\", delegate: nil, cancelButtonTitle: nil, otherButtonTitles: \"Ok\").show()\n            }\n        })\n        \n    }\n    \n    override func viewWillDisappear(_ animated: Bool) {\n        self.scanner?.stopScanning()\n        \n        super.viewWillDisappear(animated)\n    }\n}\n```\n\nTo start scanning with a particular camera (front or back):\n\n```swift\ntry self.scanner?.startScanning(with: .front,\n    resultBlock: { codes in\n        if let codes = codes {\n            for code in codes {\n                let stringValue = code.stringValue!\n                print(\"Found code: \\(stringValue)\")\n            }\n        }\n```\n\n---\n\n## Usage in Swift 2.3 Projects\n\n```swift\nimport UIKit\nimport MTBBarcodeScanner\n\nclass ViewController: UIViewController {\n\n    var scanner: MTBBarcodeScanner?\n\n    override func viewDidLoad() {\n        super.viewDidLoad()\n\n        scanner = MTBBarcodeScanner(previewView: self.view)\n    }\n    \n    override func viewDidAppear(animated: Bool) {\n        super.viewDidAppear(animated)\n\n        scanner?.startScanningWithResultBlock({ (codes) in\n\t            for code in codes {\n\t                print(code)\n\t            }\n            }, error: nil)\n    }\n}\n```\n\n---\n\n## Tap to Focus\n\nBy default, MTBBarcodeScanner will allow the user to tap the screen to focus the camera. To disable this functionality, set the `allowTapToFocus` property to NO. To be notified when the user taps the screen, provide a block for the `didTapToFocusBlock` property, like so:\n\n```objective-c\nself.scanner.didTapToFocusBlock = ^(CGPoint point){\n    NSLog(@\"The user tapped the screen to focus. \\\n          Here we could present a view at %@\", NSStringFromCGPoint(point));\n};\n```\n\n---\n\n## Switching Cameras\n\nSwitch to the opposite camera with the `flipCamera` method on the scanner:\n\n```objective-c\n\n- (IBAction)switchCameraTapped:(id)sender {\n    [self.scanner flipCamera];\n}\n\n```\n\n\nOr specify the camera directly using `setCamera:error`, like so:\n\n```objective-c\n\nNSError *error = nil;\nMTBBarcodeScanner *scanner = [[MTBBarcodeScanner alloc] initWithPreviewView:_previewView];\n[scanner setCamera:MTBCameraFront error:\u0026error];\n\n```\n\nExamples for these are in the demo project.\n\n---\n\n## Freezing Capture\n\nUnder some circumstances you may want to freeze the video feed when capturing barcodes. To do this, call the `freezeCapture` and `unfreezeCapture` methods.\n\n---\n\n## Limiting the Scan Zone\n\nTo limit the section of the screen that barcodes can be scanned in, set the `scanRect` property on MTBBarcodeScanner inside the `didStartScanning` callback block. See `MTBAdvancedExampleViewController` for a working example of this.\n\n```\n__weak MTBAdvancedExampleViewController *weakSelf = self;\nself.scanner.didStartScanningBlock = ^{\n    weakSelf.scanner.scanRect = weakSelf.viewOfInterest.frame;\n};\n```\n\n---\n\n## Controlling the Torch\n\nTo control the torch, set the `torchMode` property or call the `toggleTorch` method.\n\nAvailable values include:\n\n```objective-c\nMTBTorchModeOff,\nMTBTorchModeOn,\nMTBTorchModeAuto\n```\n\n---\n\n## Capturing Still Images\n\nTo capture a still image, call the `captureStillImage:` method after you've started scanning.\n\n---\n\n## Design Considerations\n\nThe primary goals of this library are to:\n\n- Provide an easy-to-use interface for barcode scanning\n- Make as few assumptions about the scanning process as possible\n\t- Don't assume the user wants to scan one code at a time\n\t- Don't assume the camera input view should be a particular size\n\t- Don't assume the scanning process will have it's own view controller\n\n## Developer\n\nMike Buss\n- [Website](http://mikebuss.com)\n- [GitHub](https://github.com/mikebuss)\n- [Twitter](https://twitter.com/michaeltbuss)\n- [Email](mailto:mike@mikebuss.com)\n\n## License\n\nMTBBarcodeScanner is available under the MIT license. See the LICENSE file for more info.\n","funding_links":[],"categories":["Objective-C  Stars 1000以内排名整理"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmikebuss%2FMTBBarcodeScanner","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmikebuss%2FMTBBarcodeScanner","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmikebuss%2FMTBBarcodeScanner/lists"}