Я создал проект с панелями вкладок в Obj-C XCode, а затем просто хочу импортировать приложение сканера штрих-кода в свой проект.Я наконец-то получил ошибку, когда сказал себе: «Да, это сработает».Можете ли вы помочь выяснить это?
import UIKit
import AVFoundation
class Barcode: UIViewController, AVCaptureMetadataOutputObjectsDelegate {
@IBOutlet var videoPreview: UIView!
var stringURL = String()
enum error: Error {
case noCameraAvailable
case videoInputInitFail
}
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
do{
try scanQRCode() /* I take error message right here "Use unresolved identifier"*/
}
catch{
print("Tarama Gerçekleşemedi!")
}
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
func metadataOutput(_ output: AVCaptureMetadataOutput, didOutput metadataObjects: [AVMetadataObject], from connection: AVCaptureConnection){
if metadataObjects.count > 0 {
let machineReadableCode = metadataObjects[0] as! AVMetadataMachineReadableCodeObject
if machineReadableCode.type == AVMetadataObjectTypeQRCode {
stringURL = machineReadableCode.stringValue!
performSegue(withIdentifier: "openLink", sender: self)
}
}
}
func scanQRCode()
throws {
let avCaptureSession = AVCaptureSession()
guard let avCaptureDevice = AVCaptureDevice.defaultDevice(withMediaType: AVMediaTypeVideo) else{
print("Kamera Bulunamadı!")
throw error.noCameraAvailable
}
guard let avCaptureInput = try? AVCaptureDeviceInput(device: avCaptureDevice)
else{
print("Kameraya Erişilemedi!")
throw error.videoInputInitFail
}
let avCaptureMetadataOutput = AVCaptureMetadataOutput()
avCaptureMetadataOutput.setMetadataObjectsDelegate(self, queue: DispatchQueue.main)
avCaptureSession.addInput(avCaptureInput)
avCaptureSession.addOutput(avCaptureMetadataOutput)
avCaptureMetadataOutput.metadataObjectTypes = [AVMetadataObjectTypeQRCode]
let avCaptureVideoPreviewLayer = AVCaptureVideoPreviewLayer(session: avCaptureSession)
avCaptureVideoPreviewLayer?.videoGravity = AVLayerVideoGravityResizeAspectFill
avCaptureVideoPreviewLayer?.frame = videoPreview.bounds
self.videoPreview.layer.addSublayer(avCaptureVideoPreviewLayer!)
avCaptureSession.startRunning()
}
func prepare(for segue: UIStoryboardSegue, sender: Any?){
if segue.identifier == "openLink"{
let destination = segue.destination as! WebViewController
destination.url = URL(string: stringURL)
}
}
}
}
Мои основные классы ViewController - Obj-C, но я создал barcode.swift для barcode-tab.Эта ошибка об этом или нет?