check which Apple ID is currently logged in to iCloud?

How do I check which Apple ID (email address) is currently logged in to iCloud in Swift on iOS?

Accepted Reply

Getting the recordName would still not help me know if the correct user is using the device for me to install the data on. I have found out that I could use discoverUserIdentity(withEmailAddress:_:) and that allows me to check if the user with the unique Apple ID is signed in to iCloud on that device. If the method returns nil for error then I know I have the right device. I just need to get the email address from the user that he/she uses as his Apple ID.

Replies

You can't get the email adress. You can get a unique identifier that aligns with the Apple ID. You can also get notified when that user changes.

Can you tell me how to find that unique identifier or where I can find the information on how to do that?

NSFileManager* fileManager = [NSFileManager defaultManager];

id currentiCloudToken = fileManager.ubiquityIdentityToken


https://developer.apple.com/library/content/documentation/General/Conceptual/iCloudDesignGuide/Chapters/iCloudFundametals.html#//apple_ref/doc/uid/TP40012094-CH6-SW1

I need to do something with code if my app is installed on a specific user's device. Would Apple allow me to write code that takes the value of ubiquityIdentityToken and allows the user to email it to me using MFMailComposeViewController?

Why would you want to do that?

I need to install private data in Core Data for my app for just one particular user. Any way you can suggest would be appreciated.

What you would want to do is use the fetchUserRecordID function on CKContainer which will give you an opaque record ID for the signed in user. It's not their email address, but it's a unique identifier you can use to identify a user. This is the same value that would show up in the CK dashboard under the User column. When you get the completion handler called, you can ask the CKRecordID for the recordName, and that's the string you'd want to have. Again, it's completely opaque to you, it's just an identifier. As a previous poster stated, you don't have programmatic access to the user's email address since that would be a privacy issue.

Getting the recordName would still not help me know if the correct user is using the device for me to install the data on. I have found out that I could use discoverUserIdentity(withEmailAddress:_:) and that allows me to check if the user with the unique Apple ID is signed in to iCloud on that device. If the method returns nil for error then I know I have the right device. I just need to get the email address from the user that he/she uses as his Apple ID.