简体   繁体   中英

Type does not conform to protocol 'AVCaptureFileOutputRecordingDelegate'

I am trying to use AVCaptureMovieFileOutput.startRecordingToOutputFileURL to record audio to a file, and the syntax for the function asks for a variable of type "AVCaptureFileOutputRecordingDelegate." All of the help I've seen from this site says that you need to make a class an extension of AVCaptureFileOutputRecordingDelegate, and NSObject.

Problem is, I always get the error: Type 'AVRecordDevices' does not conform to protocol 'AVCaptureFileOutputRecordingDelegate'

How do I fix it?

有错误的类

PS I am developing for OS X if that means anything in this situation.

Updated answer for Swift 4.0:

Apple documentation .

import AVFoundation

extension ViewController: AVCaptureFileOutputRecordingDelegate {
    func fileOutput(_ output: AVCaptureFileOutput,
                    didFinishRecordingTo outputFileURL: URL,
                    from connections: [AVCaptureConnection],
                    error: Error?) {
        // Handle output
    }
}

Original answer for Swift 3.0:

func capture(_ captureOutput: AVCaptureFileOutput!, 
    didFinishRecordingToOutputFileAt outputFileURL: URL!, 
    fromConnections connections: [Any]!, 
    error: Error!) { }

It means that you don't have the proper methods implemented in your view controller:

By taking a closer look at apple´s docs you'll see that is mandatory to have at least this:

  func captureOutput(captureOutput: AVCaptureFileOutput!, didFinishRecordingToOutputFileAtURL outputFileURL: NSURL!, fromConnections connections: [AnyObject]!, error: NSError!)
    {
    }

https://developer.apple.com/library/ios/documentation/AVFoundation/Reference/AVCaptureFileOutputRecordingDelegate_Protocol/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM