Search code examples
swiftcloudkit

How to grant discoverUserInfoWithUserRecordID permission?


To retrieve actual logged in iCloud user's info via CloudKit, I need to call the discoverUserInfoWithUserRecordID method.

Its API says:

The user must have granted the CKApplicationPermissionUserDiscoverability permission for this container.

How does it work?


Solution

  • var defaultContainer = CKContainer.defaultContainer()
    var publicDatabase = defaultContainer.publicCloudDatabase
    defaultContainer.requestApplicationPermission(.PermissionUserDiscoverability, {status, error in 
    
    })
    

    Requests the specified permission from the user asynchronously.

    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. This method runs asynchronously and delivers the results to the block you provide.