0

So I'm trying to build a very simple QR code app on this new xcode. I've used the same code on swift 3 and it worked just fine. I'm trying to make it happen in swift 4, but I can't seem to find a solution. I get thrown back this error message

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

I'm guessing that it's saying that it doesn't support the metadatatype of QR. But I don't of a way to make xcode 9 utilize the QR metadata type.

Here is the super simple code I'm using, Can anyone please help me out

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()

}

}
markwalker_
  • 12,078
  • 7
  • 62
  • 99
  • could this be related to https://stackoverflow.com/a/46226088/22147 ? – Rhythmic Fistman Sep 19 '17 at 07:17
  • I am having the same issue. It does not appear to be related to the Apple bug referred to above. But that does seem to make sense. Hoe=wever, "__" does not help. In fact it tells me that AVCaptureMetaDataOutput has not member "__metatdataObjectTypes" – addzo Sep 25 '17 at 11:19

0 Answers0