QRCodeScanner83
简单的、可扩展的 iOS 应用二维码/条形码等扫描仪。
安装
CocoaPods (iOS 10+)
您可以使用 CocoaPods 通过将其添加到您的 Podfile
来安装 Keychain83
将以下行添加到您的 Podfile
。
pod 'QRCodeScanner83'
例如如下所示
platform :ios, '10.0'
use_frameworks!
target 'MyApp' do
pod 'QRCodeScanner83'
end
您可以直接提供库的路径
platform :ios, '10.0'
use_frameworks!
target 'MyApp' do
pod 'QRCodeScanner83', :git => 'https://github.com/seriyvolk83/QRCodeScanner.git'
end
用法
- 将
NSCameraUsageDescription
添加到Info.plist
,例如
<key>NSCameraUsageDescription</key>
<string>Will scan QR codes</string>
- 在 XIB 中创建视图控制器并将其类设置为
CodeScannerViewController
,并指定标识符,例如CodeScannerViewController
- 添加视图,将其类设置为
CameraPreviewView
,并将其与previewView
接口连接。 - 在代码中实例化
CodeScannerViewController
并使用公共变量和回调进行配置,例如,您至少需要定义callbackCodeScanned
。 - 可选配置
-
codeTypes
- 以限制识别的代码类型
-
delegate
- 以处理扫描仪的不同状态(添加import AVFoundation
)
- 在
callbackCodeScanned
回调中关闭视图控制器。
import QRCodeScanner83
import AVFoundation
...
guard let vc = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(identifier: "CodeScannerViewController") as? CodeScannerViewController else {
return
}
vc.callbackCodeScanned = { code in
print("SCANNED CODE: \(code)")
vc.dismiss(animated: true, completion: nil)
}
self.present(vc, animated: true, completion: nil)
更新
您可以通过请求所需更改,我会很高兴帮助您实现。
请考虑通过“♡ 赞助”按钮捐赠一些美元。