Hi I followed a course by Jared Davidson to create a custom camera view and save pictures using AVFoundation. https://www.youtube.com/watch?v=w0O3ZGUS3pk
However I would
For the sound recording issue,
Add this code when creating the captureSession
askMicroPhonePermission(completion: { (isMicrophonePermissionGiven) in
if isMicrophonePermissionGiven {
do {
try self.captureSession.addInput(AVCaptureDeviceInput(device: self.captureAudio))
} catch {
print("Error creating the database")
}
}
})
////////////////////////////////////////////////////////////////
askMicroPhonePermission function is as follows
func askMicroPhonePermission(completion: @escaping (_ success: Bool)-> Void) {
switch AVAudioSession.sharedInstance().recordPermission() {
case AVAudioSessionRecordPermission.granted:
completion(true)
case AVAudioSessionRecordPermission.denied:
completion(false) //show alert if required
case AVAudioSessionRecordPermission.undetermined:
AVAudioSession.sharedInstance().requestRecordPermission({ (granted) in
if granted {
completion(true)
} else {
completion(false) // show alert if required
}
})
default:
completion(false)
}
}
And you have to add NSMicrophoneUsageDescription key value in info.plist file.