6

As per the apple standard, we need to ask permission to access user camera. so I have successfully integrated camera and it is working fine in iOS 11. but currently, I am testing camera feature and found that if user one time allowed camera access, The same app will not ask for permission even after fresh installed(from app store).

so my question is, is it behavious changed in iOS 12 or we need to do some setup to asked permission every time when user try to install fresh App?

Thanks

rmaddy
  • 314,917
  • 42
  • 532
  • 579
Jatin Patel - JP
  • 3,725
  • 2
  • 21
  • 43
  • related question: https://stackoverflow.com/questions/52622481/ios-12-camera-working-without-camera-permission-dialog-box – Scriptable Oct 03 '18 at 08:17
  • @Scriptable, unfortunately it's look similar question. – Jatin Patel - JP Oct 03 '18 at 09:14
  • I have the same problem with iOS 12, did you fix it? – CGR Nov 29 '18 at 15:54
  • @CGR, I think in iOS 12, Apple changed behavior. If you granted permission at once they are not asking for permission second time everafter fresh installed. It will stored at OS level may be with bundle identifier. – Jatin Patel - JP Nov 30 '18 at 06:39
  • @JatinPatel Yes, I am also facing the same issue, my app got rejected due to accessing privacy sensitive data and they said i did not included NSCameraUsageDescription in plist. But it was there in the project, and it is not popping up the default permission alert. – R. Mohan Dec 02 '18 at 06:02
  • @JatinPatel Did you fix it?. Having same problem with IOS 12 – Vikky Dec 05 '18 at 07:30
  • @Vikky, still not fixed it. even though apple will approved my app. – Jatin Patel - JP Dec 05 '18 at 09:01
  • @JatinPatel I can't find anywhere that its a behaviour, but now when I checked in IOS 10 still the same behaviour continues. – Vikky Dec 05 '18 at 09:31
  • @Vikky, for iOS 10, It is working fine in my case. – Jatin Patel - JP Dec 07 '18 at 11:53
  • @JatinPatel Did you find the solution? I still have the same bug only in iOS 12.1 – Zgpeace Feb 20 '19 at 10:51

1 Answers1

1

iOS 12.1 / Swift 4.2

Every time the user taps on the Camera button in your app, you call this code. It firstly asks for permissions, and if the settings are still there from the past installs, UIAlertController pops up, allowing the user to open the Settings app on the device, and change camera permission settings.

OnCameraOpenButtonTap()

if UIImagePickerController.isSourceTypeAvailable(.camera) {
   checkCameraAccess(isAllowed: {
            if $0 {
                DispatchQueue.main.async {
                    self.presentCamera()
                }
            } else {
                DispatchQueue.main.async {
                self.presentCameraSettings()
            }
        }
    })
}

func checkCameraAccess(isAllowed: @escaping (Bool) -> Void) {
    switch AVCaptureDevice.authorizationStatus(for: .video) {
    case .denied:
        isAllowed(false)
    case .restricted:
        isAllowed(false)
    case .authorized:
        isAllowed(true)
    case .notDetermined:
        AVCaptureDevice.requestAccess(for: .video) { isAllowed($0) }
    }
}

private func presentCamera() {
    let imagePicker = UIImagePickerController()
    imagePicker.delegate = self
    imagePicker.sourceType = .camera
    present(imagePicker, animated: true, completion: nil)
}

private func presentCameraSettings() {
    let alert = UIAlertController.init(title: "allowCameraTitle", message: "allowCameraMessage", preferredStyle: .alert)
    alert.addAction(UIAlertAction.init(title: "Cancel", style: .cancel, handler: { (_) in
    }))

    alert.addAction(UIAlertAction.init(title: "Settings", style: .default, handler: { (_) in
        UIApplication.shared.open(URL(string: UIApplication.openSettingsURLString)!, options: [:], completionHandler: nil)
    }))

    present(alert, animated: true)
}
Boris Nikolic
  • 746
  • 14
  • 24