When working with the CloudKit production environment I need to be able to view data for iCloud accounts other than my development account.
I’ve been experimenting with syncing a private Core Data database with CloudKit. During development I’m building and running from Xcode on the simulator. I’m logged into the simulator with my development account:
When I login to the CloudKit Console I also use my registered development account. I can then see and query the records my user is creating on the simulator:
From the CloudKit Database page of the console select the container for the app and make sure you’re in the Development environment:
Since I’m working with a private Core Data database I need to select the private database, the coredata CloudKit zone and then the record to query.
The CloudKit records prefix the Core Data entity name with “CD_”.
When working with TestFlight or App Store release builds on a device I need to switch to the production environment (don’t forget to deploy your schema to production):
That causes me a bit of a headache. A recurring problem I have when working with iCloud is that my Apple development account is different from my personal iCloud account. That’s fine when I’m testing on the simulator. I can log into iCloud on the simulator and the CloudKit Console with my development account and see everything that is happening.
The problem comes when I want to use a TestFlight or App Store build on a device. I no longer have any spare test devices I can use so I’m using my own devices where I’m logged in with my personal iCloud account. If you do have test devices you’re probably using them with test iCloud accounts.
Either way you can’t login to the CloudKit console directly with those iCloud accounts. You can only login with a registered developer account. Luckily there’s a workaround.
Act As iCloud Account
I’m not sure when Apple added it, I first noticed it in a WWDC22 session, but the CloudKit Console does allow you to act as a different iCloud account when logged in with your developer account:
First, when working with TestFlight or App Store release builds I need the production environment of the CloudKit database:
Then use the “Act As iCloud Account…” option in the bottom left corner of the console:
Use the “Open Sign In Window”: button:
I find I need to cancel the initial sign in window to get back to the window that lets me enter my Apple ID before the login works:
When active you’ll see a banner at the top of the console. Unfortunately, it shows an internal Apple identifier rather than the Apple ID of the user you’re logged in as:
Switching containers, environment, or using the stop button will sign you out of the user.
As before, I can now select the private database, the coredata CloudKit zone and the record type to query and get results for the production user.
I can’t ever imagine asking a user to give me their iCloud account details but this is still useful if you have multiple iCloud test accounts.