Emilie BELLIER
Emilie BELLIER

Reputation: 41

Swift how to set manually photoLibrary and camera authorization?

When using my app, the user is asked permission to access camera and library one time (when needed), answering allow or not in the "apple alert" (requestAccess). I need to add a view where the user can be able to change these authorizations afterwards if he wants. I added switch buttons so the user can make the choice to keep it authorized or not. But I can't find how to set the authorizationStatus. Is there a way to change the authorizationStatus manually, from .authorized to .denied or opposite ? I tried to prompt the apple alert using 'AVCaptureDevice.requestAccess()' but it doesn't show if the user already authorized before. Any suggestion welcome :)

Upvotes: 0

Views: 83

Answers (1)

AlexSmet
AlexSmet

Reputation: 2161

By security and privacy reasons developers have only one way - use system dialog for requesting authorization for access to protected system services.

But you can suggest for your users a short way to system settings. This code launches the Settings app and displays your app’s custom settings.

let settingUrl = URL(string: UIApplication.openSettingsURLString)
DispatchQueue.main.async {
    UIApplication.shared.open(settingUrl!, options: [:], completionHandler: nil)
}

Upvotes: 2

Related Questions