Search code examples
macoscocoacloudkitcloudkit-environments

CloudKit Error: Not Authenticated on Mac but I'm Signed In


I'm using iCloud as a way to authenticate a user's identity in a Mac app. I use a bit of code to look up the user's recordName which is a unique string that helps my app know who they are without needing any personal details.

func fetchCloudKitAccessToken(completion: @escaping (_ accessToken: String?, _ error: Error?) -> Void) {

  let container = CKContainer(identifier: "iCloud.my.container.here")

  container.fetchUserRecordID { (recordID, error) in
    let token = recordID?.recordName
    completion(token, error)
  }
}

This works great on my Mac where Xcode is building the app. But when I move my app binary to other computers (where I am also signed into iCloud), I get this CKError:

CKError 0x60800024e4f0: "Not Authenticated" (9); "No iCloud account is configured"

But I am definitely signed in to iCloud. Any idea what's going on?


Solution

  • As far as I understand it, when using CloudKit (For MacOS) is different than iOS, tvOS and watchOS. To test on another computer, this computer must be registered in your portal, the iCloud account of the new testing computer also has to be a developers account, and finally your binary should be configured to run in production environment instead of development.