How do I fetch the user's iCloud email?

There seems to be an API for this, but it's always returning nil. Here's my code:


  CKContainer.default().requestApplicationPermission(.userDiscoverability) { status, error in
       CKContainer.default().fetchUserRecordID { id, error in
       guard let id = id else { return }
       CKContainer.default().discoverUserIdentity(withUserRecordID: id) { info, error in
            if let info = info {
                 print("Got an email: \(info.lookupInfo?.emailAddress ?? "-none-")
            }
       }
  }


the email address field in the lookupInfo structure is always nil. Was this functionality removed?


Thanks!
Ben

Replies

Having the same issue, any updates on this?