I am trying to take/record video asynchronously on the main thread. However, when I call dispatch.main.async
, I always get the error:
use of unresolved identifier DispatchQueue
I've looked everywhere from WWDC to Apple's Documentation, but I see no evidence of the type being deprecated.
Here is the code:
if !self.cameraEngine.isRecording {
if let url = CameraEngineFileManager.temporaryPath("video.mp4") {
self.cameraButton.setTitle("stop recording", forState: [])
self.cameraEngine.startRecordingVideo(url, blockCompletion: { (url: NSURL?, error: NSError?) -> (Void) in
if let url = url {
DispatchQueue.main.async {
self.cameraButton.setTitle("start recording", for: .normal)
CameraEngineFileManager.saveVideo(url, blockCompletion: { (success: Bool, error: Error?) -> (Void) in
if success {
let alertController = UIAlertController(title: "Success, video saved !", message: nil, preferredStyle: .alert)
alertController.addAction(UIAlertAction(title: "Ok", style: .default, handler: nil))
self.present(alertController, animated: true, completion: nil)
}
})
}
}
})
}
}
else {
self.cameraEngine.stopRecordingVideo()
}
}
You can either put
import Foundation
or
import Dispatch
at the beginning of your code to start using DispatchQueue class without any issue.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With