Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get notified when the user makes selection for allowing access to Camera in iOS

When the app tries to access the Camera API's in iOS than an OS level alertview is shown. The user here has to allow access to camera or disable the access.

My question is how can I get notified of the selection made by the user..?

Say he selected don't allow access than is there any notification raised which I can use in my app..?

Any help is appreciated.

like image 470
Ankit Srivastava Avatar asked Sep 19 '14 12:09

Ankit Srivastava


People also ask

How do I ask for camera permission iOS?

With this option, you can easily manage which app can access the camera. Step 1: Go to Settings > Privacy. Step 2: Tap on Camera to see which apps have access to it. You can allow or block apps using Camera from here.

Can iOS apps access camera without permission?

Before apps use the camera or microphone on your iPhone, they're required to request your permission and explain why they're asking. For example, a social networking app may ask to use your camera so that you can take and upload pictures to that app.

How do I enable camera access in iOS?

Open the Settings app. Tap on Safari > Camera. Scroll down to Camera & Microphone. Confirm that "Ask" or "Allow" is checked.


1 Answers

Instead of letting the OS show the alert view when the camera appears, you can check for the current authorization status, and request for the authorization manually. That way, you get a callback when the user accepts/rejects your request.

In swift:

let status = AVCaptureDevice.authorizationStatusForMediaType(AVMediaTypeVideo)
if status == AVAuthorizationStatus.Authorized {
    // Show camera
} else if status == AVAuthorizationStatus.NotDetermined {
    // Request permission
    AVCaptureDevice.requestAccessForMediaType(AVMediaTypeVideo, completionHandler: { (granted) -> Void in
        if granted {
            // Show camera
        }
    })
} else {
    // User rejected permission. Ask user to switch it on in the Settings app manually
}

If the user has previously rejected the request, calling requestAccessForMediaType will not show the alert and will execute the completion block immediately. In this case, you can choose to show your custom alert and link the user to the settings page. More info on this here.

like image 199
ken Avatar answered Oct 12 '22 22:10

ken