AdyenBarcoder
使用 Verifone 扫描仪通过 MFi。
要求
iOS 8.0 或更高版本。
安装
Cocoapods
- 将
pod 'AdyenBarcoder'
添加到您的Podfile
。 - 运行
pod install
。
Carthage
- 将
github "adyen/adyen-barcoder-ios"
添加到您的Cartfile
中。 - 运行
carthage update
。 - 按照Carthage Readme中描述的方法将框架与您的目标链接。
手动操作
从AdyenBarcoder
文件夹中复制文件。
用法
您需要在Info.plist
文件中的支持的辅助协议
中将com.verifone.pmr.barcode
添加进getParameterFromOption。
示例
要运行示例项目,首先从仓库中克隆并从项目目录运行pod install
。
初始化
要初始化Barcoder库,只需获取共享实例并设置您的BarcoderDelegate
。
let barcoder = Barcoder.sharedInstance
barcoder.delegate = self
BarcoderDelegate
唯一强制性方法是didScan(barcode:)
。扫描结果将被传递到这里。您还可以在didChange(status:)
中接收状态更新。
@objc public protocol BarcoderDelegate {
@objc func didScan(barcode: Barcode)
@objc optional func didChange(status: BarcoderStatus)
@objc optional func didReceiveLog(message: String)
}
BarcodeMode
Barcoder库支持四种模式
@objc public enum BarcoderMode: Int {
case hardwareAndSofwareButton // Default mode. Both hardware button and software commands (startSoftScan, stopSoftScan) are enabled.
case hardwareButton // Only hardware button is enabled. Calls to software commands will be ignored.
case softwareButton // Only software commands are enabled. Clicking the hardware button will not trigger the lights.
case disabled // Disabled.
}
您可以通过在Barcoder.sharedInstance
上设置mode
变量来设置模式。默认值是.hardwareAndSoftwareButton
。
SoftScan
开始软扫描
barcoder.startSoftScan()
停止软扫描
barcoder.stopSoftScan()
startSoftScan
后调用stopSoftScan
。
重要:始终在启动Logging
有五种日志级别可供选择:无、错误、信息、调试、跟踪。要设置日志级别,只需设置您的Barcoder
实例变量
barcoder.logLevel = .debug
您将通过BarcoderDelegate
方法的didReceiveLog(message:)
接收每个新的日志消息。
高级用法
交错2 of 5
您可以在Barcoder
实例上启用或禁用交错2 of 5变量设置
barcoder.interleaved2Of5 = true
自定义符号
可以使用setSymbology(enabled:=)
方法来自定义条形码符号
//Should be called AFTER .ready event on `didChange(status:)`
barcoder.setSymbology(.EN_CODE11, enabled: true)
所有接受的符号列表可以在SymPid
枚举中找到。
在Objective-C中的示例用法
//
// Do not forget to put in Podfile:
// use_frameworks!
// pod "AdyenBarcoder"
//
// And put in Info.plist file:
// "com.verifone.pmr.barcode" in the "Supported external accessory protocols"
#import <AdyenBarcoder/AdyenBarcoder-Swift.h>
@interface ViewController () <BarcoderDelegate>
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Initialize
[Barcoder sharedInstance].delegate = self;
}
// Did scanned
- (void)didScanWithBarcode:(Barcode * _Nonnull)barcode {
NSLog(@"Scanned barcode: %@", barcode.text);
}
@end
支持
如果您有任何问题、疑问或建议,请在此处创建一个问题。
许可证
MIT许可证。更多信息请参阅LICENSE文件。