0

I'm trying to build an messageExtension app and I want it to take a picture using the iphone camera. I know that I need to add the NSCameraUsageDescription in my Info.plist file and I have done that. I have tried to something similar with a normal ios app and it worked fine; however when I do it in my message app it does not work.

Here attached are some screenshots and the code i use to call to open the camera. I feel I've been running in circles so any ideas would help.

Error screenshot

Info.plist screenshot

    private func openCamera() {
        print("open camera!!!!")
        
        switch AVCaptureDevice.authorizationStatus(for: .video) {
        case .authorized: // the user has already authorized to access the camera.
            print("authorized")
            self.setupCaptureSession()
            
        case .notDetermined: // the user has not yet asked for camera access.
            print("not det")
            AVCaptureDevice.requestAccess(for: .video) { granted in
                if granted { // if user has granted to access the camera.
                    print("the user has granted to access the camera")
                    self.setupCaptureSession()
                } else {
                    print("the user has not granted to access the camera")
                    self.handleDismiss()
                }
            }
            
        case .denied:
            print("the user has denied previously to access the camera.")
            self.handleDismiss()
            
        case .restricted:
            print("the user can't give camera access due to some restriction.")
            self.handleDismiss()
            
        default:
            print("something has wrong due to we can't access the camera.")
            self.handleDismiss()
        }
    }
burnsi
  • 6,194
  • 13
  • 17
  • 27

1 Answers1

0

For anyone that is wondering about this, I found the issue. Basically you need the permission in the project level as well as the extension. I tried adding another Info.plist file but that didn't work so you can just add them in the Info tab when you click on the project (make sure that you selected the project and not the extension as the target).

This link helped: link