Search code examples
iosswiftcloudkitapple-id

How to retrieve AppleID of logged in user via CloudKit?


I figured out how to retrieve first / lastName of a logged in user. Is there a way to get the AppleID too?!

var defaultContainer = CKContainer.defaultContainer()
var publicDatabase = defaultContainer.publicCloudDatabase

    defaultContainer.discoverUserInfoWithUserRecordID(recordID, {userInfo, error in

        println("firstName: \(userInfo.firstName?) lastName: \(userInfo.lastName?)")

        })

Solution

  • You cannot retrieve the current user's email address - you're going to have to ask for it outside of CloudKit. This is a privacy thing. You're supposed to use the UserRecordId to uniquely identify users.

    You can, however, search for other users if you already know their email address with CKDiscoverUserInfosOperation.