CKError 429 from CloudKit, using CKDiscoverAllUserIdentitiesOperation

I am working with the CKDiscoverAllUserIdentitiesOperation. I would like to fetch all users, however, CloudKit returns the following error: <CKError 0x6000009ce040: "Request Rate Limited" (7/2058); "Operation throttled by previous server http 429 reply. Retry after 6432.8 seconds. (Other operations may be allowed.)"; Retry after 6432.8 seconds> Here's my code:

var identities =  [CKUserIdentity]()

let operation = CKDiscoverAllUserIdentitiesOperation()

operation.userIdentityDiscoveredBlock = { userIdentity in
    identities.append(userIdentity)
}

operation.discoverAllUserIdentitiesCompletionBlock = { error in
    if let error = error {
        fatalError(error.localizedDescription)
    } else {
       completion(identities)
    }
}

operation.qualityOfService = .userInitiated
CKContainer.default().add(operation)

App adds that operation in the viewDidAppear method . Also I have requested to the application permission for user discoverability (accodring to the Apple's documentation: https://developer.apple.com/documentation/cloudkit/ckdiscoveralluseridentitiesoperato)

if there is a question here, the answer is to do what it says "Retry after X seconds". The actual time is included in the info dictionary of the error. Here's a snippet from CloudCore, an open-source sync engine, that shows how it retrieves this info…

private func handle(error: Error, …) {
	guard let cloudError = error as? CKError else {
     …
		return
	}

	switch cloudError.code {
      case .requestRateLimited, .zoneBusy, .serviceUnavailable:            
          if let number = cloudError.userInfo[CKErrorRetryAfterKey] as? NSNumber {
              let pauseUntil = Date(timeIntervalSinceNow: number.doubleValue)
          }
       …
  }
}
CKError 429 from CloudKit, using CKDiscoverAllUserIdentitiesOperation
 
 
Q