The CKContainer.discoverAllIdentities
request always fails in my CloudKit app. It has continually failed over the course of several days.
A simplified version of the code that is failing (which results in the same error) is:
private func getContacts(completion: (([CKUserIdentity]?) -> Void)?) {
container.status(forApplicationPermission: .userDiscoverability) { [weak self] status, error in
if let error = error {
print(error)
}
switch status {
case .granted:
self?.discover(completion: completion)
default:
print("status not granted")
}
}
}
private func discover(completion: (([CKUserIdentity]?) -> Void)?) {
let op = CKDiscoverAllUserIdentitiesOperation()
op.qualityOfService = .userInitiated
op.discoverAllUserIdentitiesCompletionBlock = { error in
if let error = error {
print(error)
}
}
op.userIdentityDiscoveredBlock = { identity in
print(identity)
}
op.start()
}
It results in an error being passed to the op.discoverAllUserIdentitiesCompletionBlock
. The description of the error in the log is:
<CKError 0x1c4a51a60: "Server Rejected Request" (15/2000); server message = "Internal server error"; uuid = F67453B9-712D-4E5E-9335-929123E3C978; container ID = "iCloud.com.huntermaximillionmonk.topdraw">
Previously, this operation would work, but only for certain iCloud users. Now it's not for both of my test users.
Problem:
This was a problem in iOS
11.0
Based on my testing:
This works ok in
Xcode 9.2
/iOS 11.2.1
on the device (not simulator)After resetting the simulator works for the first time, doesn't work subsequently, however on the device it works repeatedly.
Code:
Edit:
Apple fixed this issue day after this answer was posted, coincidence?! I don't think so :)
This is not actually the answer to the question, but a fix that helped me to cross over this error. It will require you to change your app UI interaction and add ContactsUI framework to your project, moreover your user will be responsible for selecting a contact with iCloud related email.
Good news is that the method
discoverUserIdentity
is still works. So, you can use it to getCKUserIdentity
from manually selected contact.It might sound useless, but in my case, it helped me to solve the
Server Rejected Request" (15/2000)
error, to fix one of the features of my app and continue to use the other feature related code with less efforts than I thought.I hope someone will find this helpful.
Just another data point on this that might help with the overall picture. I was still seeing this error on 11.2.5 when I used my own iCloud AppleID (with hundreds of contacts) while running a Test App that called discoverAllIdentitiesWithCompletionHandler. I'd get the dreaded CKError 0x1c0051730: "Server Rejected Request" (15/2000); server message = "Internal server error". When I switched to run the exact same code on my daughters iOS11.2.5 device (with just a handful of contacts) the code worked fine. Leads me to believe there is some rate limiting going on when there are a lot of contacts with iOS11. (P.S. No errors at all running on iOS10)