# MTBBarcodeScanner
[![Version](https://img.shields.io/cocoapods/v/MTBBarcodeScanner.svg?style=flat)](http://cocoadocs.org/docsets/MTBBarcodeScanner)
[![License](https://img.shields.io/cocoapods/l/MTBBarcodeScanner.svg?style=flat)](http://cocoadocs.org/docsets/MTBBarcodeScanner)
[![Platform](https://img.shields.io/cocoapods/p/MTBBarcodeScanner.svg?style=flat)](http://cocoadocs.org/docsets/MTBBarcodeScanner)
[![Carthage Compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage)
A 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.
With this library you can:
- Supply a custom UIView for displaying camera input
- Read any number of barcodes before stopping
- Read multiple codes on the screen at the same time (2D barcodes only)
- Easily read codes with a block, including the string value and position in the preview
- Easily flip from the back to the front camera
- Toggle the device's torch on and off
- Freeze and unfreeze capture to display a still image from the camera
See demo project for examples of capturing one code, multiple codes, or highlighting codes as valid or invalid in the live preview.
---
<img src="https://raw.githubusercontent.com/mikebuss/MTBBarcodeScanner/develop/Assets/MTBBarcodeScanner.png" width=100% height=100%>
#### Sample Barcodes
<img src="https://raw.githubusercontent.com/mikebuss/MTBBarcodeScanner/develop/Assets/sample-barcodes.png" width=50% height=50%>
---
## Installation
### CocoaPods
MTBBarcodeScanner can be installed via [CocoaPods](http://cocoapods.org) by adding the following line to your Podfile:
`pod "MTBBarcodeScanner"`
### Carthage
[Carthage](https://github.com/Carthage/Carthage) is a decentralized dependency manager that builds your dependencies and provides you with binary frameworks.
You can install Carthage with [Homebrew](http://brew.sh/) using the following command:
```bash
$ brew update
$ brew install carthage
```
To integrate MTBBarcodeScanner into your Xcode project using Carthage, specify it in your `Cartfile`:
```ogdl
github "mikebuss/MTBBarcodeScanner"
```
Run `carthage update` to build the framework and drag the built `MTBBarcodeScanner.framework` into your Xcode project.
### Manual
If 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:
[`MTBBarcodeScanner.h`](https://github.com/mikebuss/MTBBarcodeScanner/blob/master/Classes/ios/Scanners/MTBBarcodeScanner.h)
[`MTBBarcodeScanner.m`](https://github.com/mikebuss/MTBBarcodeScanner/blob/master/Classes/ios/Scanners/MTBBarcodeScanner.m)
---
## Usage in Objective-C Projects
To import the library: `#import "MTBBarcodeScanner.h"`
#### Initialization
To initialize an instance of `MTBBarcodeScanner`:
```objective-c
scanner = [[MTBBarcodeScanner alloc] initWithPreviewView:self.previewView];
```
Where `previewView` is the `UIView` in which the camera input will be displayed.
If you only want to scan for certain MetaObjectTypes, you can initialize with the `initWithMetadataObjectTypes:previewView:` method:
```objective-c
s = [[MTBBarcodeScanner alloc] initWithMetadataObjectTypes:@[AVMetadataObjectTypeQRCode]
previewView:self.previewView];
```
#### iOS 10 and later
If 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:
```xml
<key>NSCameraUsageDescription</key>
<string>Can we access your camera in order to scan barcodes?</string>
```
Of course you can also set your own (localized) message here. To find out more about privacy-keys in iOS, check the
[official Apple documentation](https://developer.apple.com/library/content/documentation/General/Reference/InfoPlistKeyReference/Articles/CocoaKeys.html).
#### Scanning
To read the first code and stop scanning:
**Note:** To avoid a delay in the camera feed, start scanning in `viewDidAppear` and not `viewDidLoad`.
```objective-c
[MTBBarcodeScanner requestCameraPermissionWithSuccess:^(BOOL success) {
if (success) {
NSError *error = nil;
[self.scanner startScanningWithResultBlock:^(NSArray *codes) {
AVMetadataMachineReadableCodeObject *code = [codes firstObject];
NSLog(@"Found code: %@", code.stringValue);
[self.scanner stopScanning];
} error:&error];
} else {
// The user denied access to the camera
}
}];
```
If the camera is pointed at more than one 2-dimensional code, you can read all of them:
```objective-c
NSError *error = nil;
[self.scanner startScanningWithResultBlock:^(NSArray *codes) {
for (AVMetadataMachineReadableCodeObject *code in codes) {
NSLog(@"Found code: %@", code.stringValue);
}
[self.scanner stopScanning];
} error:&error];
```
**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).
To continuously read and only output unique codes:
```objective-c
NSError *error = nil;
[self.scanner startScanningWithResultBlock:^(NSArray *codes) {
for (AVMetadataMachineReadableCodeObject *code in codes) {
if ([self.uniqueCodes indexOfObject:code.stringValue] == NSNotFound) {
[self.uniqueCodes addObject:code.stringValue];
NSLog(@"Found unique code: %@", code.stringValue);
}
}
} error:&error];
```
#### Callback Blocks
An alternative way to setup MTBBarcodeScanner is to configure the blocks directly, like so:
```objective-c
self.scanner.didStartScanningBlock = ^{
NSLog(@"The scanner started scanning! We can now hide any activity spinners.");
};
self.scanner.resultBlock = ^(NSArray *codes){
NSLog(@"Found these codes: %@", codes);
};
self.scanner.didTapToFocusBlock = ^(CGPoint point){
NSLog(@"The user tapped the screen to focus. \
Here we could present a view at %@", NSStringFromCGPoint(point));
};
[self.scanner startScanning];
```
This is useful if you would like to present a spinner while MTBBarcodeScanner is initializing.
If you would like to reference `self` in one of these blocks, remember to use a weak reference to avoid a retain cycle:
```objective-c
__weak MyViewController *weakSelf = self;
self.scanner.resultBlock = ^(NSArray *codes){
[weakSelf drawOverlaysOnCodes:codes];
};
```
---
## Usage in Swift 3+ Projects
See the `SwiftExampleViewController.swift` file in the repository for a working example of this.
```swift
import UIKit
import MTBBarcodeScanner
class SwiftExampleViewController: UIViewController {
@IBOutlet var previewView: UIView!
var scanner: MTBBarcodeScanner?
override func viewDidLoad() {
super.viewDidLoad()
scanner = MTBBarcodeScanner(previewView: previewView)
}
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
MTBBarcodeScanner.requestCameraPermission(success: { success in
if success {
do {
try self.scanner?.startScanning(resultBlock: { codes in
if let codes = codes {
for code in codes {
let stringValue = code.stringValue!
print("Found code: \(stringValue)")
}
}
})
} catch {
NSLog("Unable to start scanning")
}
} else {
UIAlertView(title: "Scanning Unavailable", message: "This app does no
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
项目为初版,包含主体框架,界面交互部分,主要打造的是线上及线下结合的模式。 项目为初版,包含主体框架,界面交互部分,主要打造的是线上及线下结合的模式。 项目为初版,包含主体框架,界面交互部分,主要打造的是线上及线下结合的模式。 项目为初版,包含主体框架,界面交互部分,主要打造的是线上及线下结合的模式。 项目为初版,包含主体框架,界面交互部分,主要打造的是线上及线下结合的模式。 项目为初版,包含主体框架,界面交互部分,主要打造的是线上及线下结合的模式。 项目为初版,包含主体框架,界面交互部分,主要打造的是线上及线下结合的模式。 项目为初版,包含主体框架,界面交互部分,主要打造的是线上及线下结合的模式。 项目为初版,包含主体框架,界面交互部分,主要打造的是线上及线下结合的模式。 项目为初版,包含主体框架,界面交互部分,主要打造的是线上及线下结合的模式。 项目为初版,包含主体框架,界面交互部分,主要打造的是线上及线下结合的模式。 项目为初版,包含主体框架,界面交互部分,主要打造的是线上及线下结合的模式。 项目为初版,包含主体框架,界面交互部分,主要打造的是线上及线下结
资源推荐
资源详情
资源评论
收起资源包目录
flutter + getx 电商商城项目 (1776个子文件)
000fde95fa267307c03fd63f6cb64c8737613a 9KB
00c6a6d3e165899d349b9ca5923cb348976500 285B
01675941f285969dec0708b2726a8c5689c954 868B
017a6b45be59d69ab78110f5785c710365feee 261B
0191d8df64d9984a77717d19d8f09f7eb17f63 479B
03d76fcb94c6e788405f7946a9ab6c7e018afe 127B
041a1b7a1c155f07b84136e38773e21ca8f017 587B
046e75631d0b9a4ed46a50eacff7ae66d2ac3a 575B
04c372d3ce9ec5bd01062f1a814bb6076abd7d 2KB
04c3e0c70296a1359663a9c8bbf17d4ae36db1 1KB
052a7e011c2bce4a0ab08ddac8db5853cdc805 217B
0583737f4751dbb694f283d31f24a3ff8a186b 247B
0682358c8c3041c782e3bcd41c2a4565fa41cf 390B
0748cde6c3facd9a7592aba613d66736e83255 712B
07db34fa87b27decfa7984f35dec29c8a9c748 914B
07f8f1a443ef6d98eeb6a1057025efa1c75491 278B
080594aec7e8f605fb924844b50a33d9a04791 3KB
089f70cdc9ab11ef97967287246b4556497bd8 746B
08a618b843ee196982ec4ac91cb531486e59d2 300B
09acf995904bf6e366544859197208b50f0193 4KB
0aae287cbdc9a991d73486e6837b75ef07cd05 2KB
0ae769b70a374b6f6e6e1954efcac417d03a3c 49B
0c545fd8a49aefcca5e2fc97507c43e160f9fa 70B
0c830ecc1b646b515b070f9f85731a7f96c2ee 1KB
0ca5821b1ea107a71e30713f308f2de69c451a 838B
0cfc2d287ac48d70e6c511e74757c3598346b5 1KB
0dbba97f29a0d912cb5f24e1591c2883d489da 68B
0dc7cda994526863b7d7b9131aad036f0c0fb7 296B
0e6b8dcbae44803b38fd7dbb22a6017e7b396b 446B
0fe789fb648c40ef6dbbb92489a57da79f856d 1KB
10ddae080f37f41b30cf475427fc5980acceda 899B
10de1948be902e83b68029551233d555816fed 66B
11a0d456bc724442192364c5d13a9000327e5a 1KB
11ab3fac0488ba80e28dd8c118f50ec22afc2a 406B
11e5eb9e8700b717920d1004a10741f8214607 520B
12005bf16a06286eff578e9de14a672157e07d 1KB
1231a14f466e486605ff9794b68bfea5421243 1KB
129f99a38f86e6a04d1f06e5ac3efddd879a45 485B
13000a8031c1661846d64e1c4626cc0e30201c 141B
130606a6aa3e450008fb1814cc82cead7f5bae 527B
1425372af475afa1894a3922106d5cec1d7ecf 82B
156fe8b7b760f437c6f3123a222d3a639607b1 473B
157481a0e49246790d5b002a50da58870369f8 1KB
15953a7defbb7115885f8fbe9f06daaa45b86b 9KB
15e92a7ab87cc31adfda06a341c8ab48559bea 321B
1639340b419231fc40a4f1f02a5f39f0501e73 225B
172b10948135c0113a562436bdb306ffe53280 2KB
1773cd857a8a0f0c9c7d3dc3f5ff4fb298dc10 724B
1778e5e888eb94b18e1ded667f4c3b0c464636 234B
19498a67d4e901fab54c6f17cd9da1fa512a86 402B
1ae2f0a0fa26142f81e6f59c3bb370414f8624 443B
1b656120203411efa6f28d8cc21855cbeb90f6 428B
1c115364b161edab8509d2801bcdffc9e0ddcc 1KB
1c30afe9771fe9b53269af4bf43ed1b8ca2cf7 452B
1c89bd84ec48d71819dd1e2294e081ad89b508 2KB
1d34e2e4f1c02d65c7c23094794b35d483ec08 1KB
1d45f09ce965db3a3a422c17ccc834c2601209 3KB
1dfdfff6190ad3f7def0297774a7891dc43cd4 2KB
1ed1797a53440876d6192ed221c9b572fa83cd 194KB
1ef88056edd1caf99a935e434e7ff6943a0ef6 486B
1f70109455529c49e150336bbe08785cbf654e 688B
1fb5cce5cc59f487181201230df56c9fe79a86 372B
2048a6aeadad0f89cd74be99f321e070b8a793 64B
2157cae642d1914806f35188c42913e0b07a40 2KB
21f61b9249e5b5fb933283b48b8810631f42d7 615B
21fe4793f9be38cf535d9083c301542cdcd009 538B
22a284fc9a38d531426ada5c1cb504b4412ef6 140B
2342e689acd8cef959a78ce756fdb1f1f71dea 21KB
238c0b8232ed72434a8df4b45ed43780d75e41 239B
2399c591acb93dd7bdfed9c59cb379e5cc68e8 455B
23dad4a96f6922e443024578d60dfc5ebd8214 550B
240acc2de189c5c2397c391a3d7f78c64e4ffa 362B
24c559bd5b6789253f9646535188cc17768a1b 914B
24eb7dc5944279a452a37e72b4014b98f9d702 7KB
25ddc18d21b610c52708eb7146aaff097dc1c8 2KB
25e105df39e8429814f3189a8015087720cba1 333B
26268aeaa662e3d786d8c70513020f39073e9f 397B
265b14658cfecdca71447b1141b886697cd53d 6KB
2661b834bd1a596e4c1814ecce6582173114e5 7.18MB
26c733937fc88a221ca0142bd6180b07c9bb5e 1KB
2725bb3b5a46f8645af5812743cf70be1fa322 43KB
275aa8c350812abe5115f456efb65482510521 4KB
284bbabced68c3c086fad3cf2e0dc4d73c76c9 45B
28b388aded2c97713275d5067983e3853dbb09 401B
29b395dcc577e1435418523b280edfedca398e 392B
29d66ada724503dbb50c92fdc5e4ae2d536033 1KB
29e013d16d19b9e84985e57d9c650a25cdcca8 3KB
29ef18e532e6256a7376e1c794b68624c6ef06 473B
2a18124f25f45dba89ea221ccd121549c2ae14 453B
2a815c6796cf6a80cfabed7adbc8f050178d18 68KB
2adcb34c2d30f4e7e4426422385dfa72f63114 915B
2c3434e7da2f92c848858c590f059aa34e2140 233B
2c98717594534b6299f49f7c7e0096af76e4c7 1KB
2d83b2339204ad94e4cfc385bfef985a7d1bb3 535B
2dcdb251e7bf8425b08cf6ec7fc5308d7252da 50B
2e83093d85cda183062a20986889bcbbf2b4f8 1016B
2ec773922ca406f315d03bf87fa699db6896e3 730B
2edad4520942bc2ccfe3dc2002b842c99dbbf2 2KB
2f463a9bc882b461c96aadf492d1729e49e725 606B
2fd14d61de23680a7ab711f256a49916ca1e04 3KB
共 1776 条
- 1
- 2
- 3
- 4
- 5
- 6
- 18
资源评论
半身风雪
- 粉丝: 2w+
- 资源: 5
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功