In my camera app, I click a photo and press the use photo button. When the user presses the "Use Photo" button after clicking the photo, the photo gets saved in the photo library(if the user allows the app to) but the CameraView completely freezes. Here are parts of the code that might help:
ContentView:
struct ContentView: View {
var body: some View {
CameraView()
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
Part of the CameraView:
extension CameraView {
class Coordinator : NSObject, UIImagePickerControllerDelegate, UINavigationControllerDelegate {
var parent: CameraView
init(_ parent: CameraView) {
self.parent = parent
}
func imagePickerControllerDidCancel(_ picker: UIImagePickerController) {
fatalError("Cancel button pressed!")
}
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) {
if let image = info[UIImagePickerController.InfoKey.originalImage] as? UIImage {
UIImageWriteToSavedPhotosAlbum(image, nil, nil, nil)
CustomizeView()
}
}
}
}
This is the block of code where Use Photo is controlled
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) {
if let image = info[UIImagePickerController.InfoKey.originalImage] as? UIImage {
UIImageWriteToSavedPhotosAlbum(image, nil, nil, nil) //Where the CameraView freezes after this.
}