malena
malena

Reputation: 948

How to re-ask user for discoverability permission after they had denied it the first time?

The cloudkit CKContainer requestApplicationPermission() method shows an Alert to ask the user for his discoverability permission only ONCE based on the documentation and any future invocations of this method do not show the Alert any longer.

From documentation at : CKContainer.requestApplicationPermission() "The first time you request a permission on any of the user’s devices, the user is prompted to grant or deny the request. Once the user grants or denies a permission, subsequent requests for the same permission (on the same or separate devices) do not prompt the user again."

So, what happens if the user changes his mind, and I want my application to ask the user if he has changed his mind and show the alert again, how can that happen? There has to be a way, but I can'f find any documentation about it.

Upvotes: 1

Views: 832

Answers (1)

Yann Bodson
Yann Bodson

Reputation: 1654

First, check if the user has previously denied the permission with:

CKContainer.statusForApplicationPermission()

If the status returned in the completionHandler is CKApplicationPermissionStatus.Denied, show a UIAlertController asking if the user wants to enable it in settings.

If the user says yes, you can go to your app settings page like this:

if let settingsURL = NSURL(string: UIApplicationOpenSettingsURLString) {
    UIApplication.sharedApplication().openURL(settingsURL)
}

Upvotes: 1

Related Questions