AVmetadata随着快速4 xcode 9的变化而变化

时间:2017-09-18 18:55:14

标签: swift avfoundation

所以我试图在这个新的xcode上构建一个非常简单的QR码应用程序。我在swift 3上使用了相同的代码,它运行得很好。我试图在快速4中实现它,但我似乎无法找到解决方案。我被抛回这个错误消息

2017-09-18 14:41:55.269242-0400 camTest[4401:2234792] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[AVCaptureMetadataOutput setMetadataObjectTypes:] Unsupported type found - use -availableMetadataObjectTypes'
*** First throw call stack:
(0x18392bd38 0x182e40528 0x18925e7d8 0x1049d25fc 0x1049d3664 0x18cd3abfc 0x18cd3a7d4 0x18d8c78b0 0x18d07d3b0 0x18d0ad034 0x18d0aff54 0x18d0b0488 0x18d0afea4 0x18ce1a55c 0x18d0b3d60 0x18d4de084 0x18d64b620 0x18d64b4c4 0x18d64b798 0x18cd6f20c 0x18cd6f18c 0x18cd59f4c 0x18cd6ea80 0x18cd6e5a0 0x18cd69a70 0x18cd3b078 0x18d67af98 0x18d67d408 0x18d676574 0x1838d4358 0x1838d42d8 0x1838d3b60 0x1838d1738 0x1837f22d8 0x185683f84 0x18cd9e880 0x1049d5644 0x18331656c)
libc++abi.dylib: terminating with uncaught exception of type NSException

我猜它说它不支持QR的元数据类型。但我没有办法让xcode 9使用QR元数据类型。

以下是我使用的超级简单代码,任何人都可以帮助我

import UIKit
import AVFoundation

class scannerVC: UIViewController, AVCaptureMetadataOutputObjectsDelegate {

@IBOutlet weak var Square: UIImageView!


override func viewDidLoad() {
    super.viewDidLoad()

    var video = AVCaptureVideoPreviewLayer()

    let session = AVCaptureSession()

    let captureDevice = AVCaptureDevice.default(for: AVMediaType.video)

    do {

        let input = try AVCaptureDeviceInput(device: captureDevice!)
        session.addInput(input)
    } catch {
        print(error)
    }


    let output = AVCaptureMetadataOutput()

    output.setMetadataObjectsDelegate(self, queue: DispatchQueue.main)

    output.metadataObjectTypes = [AVMetadataObject.ObjectType.qr]

    video = AVCaptureVideoPreviewLayer(session: session)
    video.frame = view.layer.bounds
    view.layer.addSublayer(video)

    self.view.bringSubview(toFront: Square)
    session.startRunning()

}

}

0 个答案:

没有答案