Инициирование GMVDetector не удается
Я использую GoogleMobileVision/ детектор штрих-кода в своем проекте Swift 3.1, используя следующий код:
GMVDetector(ofType: GMVDetectorTypeBarcode, options: nil)
но в журнале это показывает:
Кажется, что GoogleMobileVision в iOS является закрытым исходным кодом, поэтому я не могу понять, что происходит на стороне реализации
Есть мысли о том, что, возможно, происходит здесь?
2 ответа
Я думаю, что вам нужно поставить какое-то необязательное значение типа штрих-кода, например, EAN13 или QRcode вместо nil.
var detector = GMVDetector()
let options:[AnyHashable: Any] = [GMVDetectorBarcodeFormats : GMVDetectorBarcodeFormat.EAN13.rawValue]
self.detector = GMVDetector.init(ofType: GMVDetectorTypeBarcode, options: options)
Отредактировано - решено
Проблема была в этом куске кода (как сказал @Developer)
let detectorOptions = [
GMVDetectorBarcodeFormats : GMVDetectorBarcodeFormat.qrCode.rawValue
]
У меня та же проблема, но безуспешно, я не знаю, что происходит.
Похоже, что это должно быть что-то настолько простое, но я думаю, что я пытался всячески это реализовать. Я искал быстрые примеры, но я не нашел ничего полезного.
var barcodeDetector : GMVDetector?
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
let detectorOptions = [
GMVDetectorBarcodeFormats : [
GMVDetectorBarcodeFormat.qrCode.rawValue
]
]
self.barcodeDetector = GMVDetector(ofType: GMVDetectorTypeBarcode, options: detectorOptions)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
}
override func viewDidAppear(_ animated: Bool) {
if let image = UIImage(named: "QRTest.png") {
if let barcodes = self.barcodeDetector!.features(in: image, options: nil) {
for barcode in barcodes {
print("\(barcode.description)")
}
}
}
}