You can use a UIImagePickerController with sourceType.camera. This opens a pre built camera from apple with which you are able to take pictures.
This would be the function:
func camera() {
if UIImagePickerController.isSourceTypeAvailable(.camera) {
let myCameraController = UIImagePickerController()
myCameraController.delegate = self
myCameraController.sourceType = .camera
self.present(myCameraController, animated: true, completion: nil)
}
}
To use UIImagePickerController you have to set UIImagePickerControllerDelegate and UINavigationControllerDelegate in your class and call this function in ViewDidLoad
Hope that this solved your problem