Mister Mister Mister Mister - 9 months ago 106
Swift Question

What makes a user discoverable to CKDiscoverAllUserIdentitiesOperation?

I am trying to discover contacts for a user with the code below (the code is in an implementation of a

. I put breakpoints in both code blocks, and I determined that the the
is not called while the completionBlock is called. This indicates that the operation is being run as expected, it just isn't finding any contacts.

I am running on the simulator, but I verified that the simulator has synced all my iCloud contacts (opening the Contacts app on the simulator shows all my contacts).

override func viewDidLoad() {

let op = CKDiscoverAllUserIdentitiesOperation()

op.discoverAllUserIdentitiesCompletionBlock = { error -> Void in
// reload my data table

op.userIdentityDiscoveredBlock = { user -> Void in
if user.hasiCloudAccount {
} else {


So my question is this - Is there something else that has to be done in order to discover contacts? Is this a simulator issue?

I searched the documentation and other questions but I can't seem to find information on this given the operation is new to iOS 10.

Answer Source

There's quite a bit that must be done before CKDiscoverAllUserIdentitiesOperation will return any results.

First, each user of your app must grant permission to be looked up by email. Your app makes this request using CKContainer requestApplicationPermission.

Each user of your app must also be logged into an iCloud account. iCloud Drive must also be enabled by the user.

And lastly, for CKDiscoverAllUserIdentitiesOperation to return any users, the person must have contacts with email addresses that match other users that completed all of the previous steps.