2

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?)")

        })
dibi
  • 3,257
  • 4
  • 24
  • 31
János
  • 32,867
  • 38
  • 193
  • 353
  • By Apple Id, you mean the user's email address? – Undo Jul 16 '14 at 20:07
  • yes, user's e-mail address what you use to log in on the authentication window – János Jul 16 '14 at 20:08
  • 2
    I believe that's the whole point of the UserRecordId, so that apple would give you some sort of mechanism to track that user in the context of your application, but without the need for the user to give out too much private information, like his email address. – carlossless Jul 16 '14 at 20:10

1 Answers1

5

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.

Undo
  • 25,519
  • 37
  • 106
  • 129
  • Hey, CKDiscoverUserInfosOperation sounds great but I can't find anything about it. Could you show how I can check whether the user's email address is same a string using this class? – LinusGeffarth Dec 02 '15 at 17:20
  • @LinusG. I'm not really sure how to do that - I've only played around with CloudKit a little bit. That might be worth asking a new question, though. – Undo Dec 03 '15 at 19:54