I am trying to prevent AVCaptureSession from adding an AVCaptureMovieFileOutput when there is not enough disk space left. I'm using the following code inside viewDidload for testing:
let session = AVCaptureSession()
session.sessionPreset = AVCaptureSessionPresetHigh
let movieFileOutput = AVCaptureMovieFileOutput()
movieFileOutput.minFreeDiskSpaceLimit = 1024 * 1024 * 100 // 100 MB
movieFileOutput.maxRecordedDuration = CMTimeMakeWithSeconds(45, Int32(NSEC_PER_SEC)) // 45 sec
if (session.canAddOutput(movieFileOutput)) {
print("Output added")
session.addOutput(movieFileOutput)
} else {
print("Not enough disk space??")
}
But somehow the function 'canAddOutput' always returns true. I'm testing it on a real device and only have 69.4 MB space left. Why is it not returning false?
From the AVCaptureOutput
header file, on minFreeDiskSpaceLimit
:
Specifies the minimum amount of free space, in bytes, required for recording to continue on a given volume.
The error is reported via the captureOutput:didFinishRecordingToOutputFileAtURL:fromConnections:error:
delegate method.
So the fact that minFreeDiskSpaceLimit
defines a condition for continued recording and the error is reported via a finish delegate method suggests to me that you must first start the capture session to use it.