Giter VIP home page Giter VIP logo

Comments (3)

dilizarov avatar dilizarov commented on June 6, 2024

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.

from dkimagepickercontroller.

zhangao0086 avatar zhangao0086 commented on June 6, 2024

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

from dkimagepickercontroller.

zhangao0086 avatar zhangao0086 commented on June 6, 2024

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

from dkimagepickercontroller.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.