CloudKit Discover User with Email

301 views Asked by At

I am using the CKOperation below to find a user record by their email. Every time I run the code it always returns the user's found as nil. I know that the email address is correct. Do you know where I could be going wrong or if there is an error with CloudKit?

Thank you

let operation = CKDiscoverUserInfosOperation()

        operation.qualityOfService = .UserInitiated
        operation.emailAddresses = ["[email protected]"]

        operation.discoverUserInfosCompletionBlock = { [unowned self] (userInfoString, userInfoID, error) in
            if error != nil {
                dispatch_async(dispatch_get_main_queue()) {
                    //Update UI Here
                    let alert = UIAlertView(title: "Error", message: "Unable to fetch data. Please try again later.", delegate: self, cancelButtonTitle: "Okay").show()
                }
            } else {
                print("Info string: \(userInfoString)")
                print("Info: \(userInfoID)")
            }
        }

        container.addOperation(operation)

I have also added this in the viewDidLoad:

CKContainer.defaultContainer().requestApplicationPermission(CKApplicationPermissions.UserDiscoverability,
                                                                completionHandler: {
                                                                    applicationPermissionStatus, error in
    })
0

There are 0 answers