Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Please Allow Camera Access shows in camera view even if accepted allowing access. #31

Closed
dilizarov opened this issue Oct 20, 2015 · 3 comments

Comments

@dilizarov
Copy link

For what it is worth, I'm using the version where you haven't created DKCamera, so I don't know if new versions fix this, but this is a problem I've run into. The only way to get rid of it is to close the app, reopen and then try again.

If I decide not to accept allowing access, I see the prompt again, it takes me to settings, but when I change the settings, then go back to app, the prompt is still there.

Does DKCamera fix this?

Edit: I just checked and DKCamera doesn't seem to have this fixed.

@dilizarov
Copy link
Author

Upon further examination, I think this is because if not authorized, a overlay is placed on the camera view. The current way doesn't care if the user allows for camera use because the overlay was already set. I think a better way is to only allow one to see the Camera view if they have authorized it. Otherwise, don't let them get there.

I think the following way is a good way to handle it.

The following code should suffice:

let authorizationState = AVCaptureDevice.authorizationStatusForMediaType(AVMediaTypeVideo)

switch authorizationState {
case .Authorized:
    self.presentViewController(pickerController, animated: true, completion: nil)
case .Denied:
    let appName =  NSBundle.mainBundle().infoDictionary?["CFBundleName"] as! String
    let alertTitle = "\"\(appName)\" Would Like to Access the Camera"

    let alert = UIAlertController(title: alertTitle, message: nil, preferredStyle: .Alert)

    let dontAllowAction = UIAlertAction(title: "Don't Allow", style: .Default, handler: nil)
    let goToSettingsAction = UIAlertAction(title: "Go To Settings", style: .Default, handler: { alert in
        UIApplication.sharedApplication().openURL(NSURL(string:UIApplicationOpenSettingsURLString)!)
    })

    alert.addAction(goToSettingsAction)
    alert.addAction(dontAllowAction)

    self.presentViewController(alert, animated: true, completion: nil)
case .NotDetermined:
    AVCaptureDevice.requestAccessForMediaType(AVMediaTypeVideo, completionHandler: { granted in
        if granted {
            dispatch_async(dispatch_get_main_queue()) {
                self.presentViewController(pickerController, animated: true, completion: nil)
            }
        }
    })
case .Restricted:
    let alert = UIAlertController(title: "Feature is Restricted on this Device", message: nil, preferredStyle: .Alert)

    let dismissAction = UIAlertAction(title: "OK", style: .Cancel, handler: nil)

    alert.addAction(dismissAction)

    self.presentViewController(alert, animated: true, completion: nil)
}

Of course, you changed your solution to use DKCamera, so you'll need to refine it a bit to be able to inject this somewhere, but the logic holds.

@zhangao0086
Copy link
Owner

@dilizarov
Thanks for your solution! I'll check it! I think this will help me. Thanks again :)

@zhangao0086
Copy link
Owner

I will release the 3.0.0 with Photos framework. develop. I believe this will improve the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants