swift3.2升级到swift4.0 扫码不走回调方法

来源:互联网 发布:计算机协议端口 编辑:程序博客网 时间:2024/05/21 10:06

xcode升级到9.0 swift改到swift4.0之后扫码一直不走回调 ,研究了好长时间,发现苹果把扫码的代理方法的参数变了之前的方法

func captureOutput(_ captureOutput: AVCaptureOutput!, didOutputMetadataObjects metadataObjects: [Any]!, from connection: AVCaptureConnection!)

func captureOutput(_ captureOutput: AVCaptureOutput!, didOutputSampleBuffer sampleBuffer: CMSampleBuffer!, from connection: AVCaptureConnection!)

这是之前swift3.2的代理方法,swift4.0之后不会走这两个代理方法,原因是现在代理方法不一样了

func metadataOutput(_ output:AVCaptureMetadataOutput, didOutput metadataObjects: [AVMetadataObject], from connection:AVCaptureConnection)

func captureOutput(_ output:AVCaptureOutput, didOutput sampleBuffer: CMSampleBuffer, from connection: AVCaptureConnection)


swift4.0的两个代理方法对比之前的3.2方法,可以发现现在方法的参数变了

将之前的两个方法的参数改好,扫码就可以正常用了

原创粉丝点击