Reputation: 21
I am trying to get the CloudKit User's first and last name.
Here is the code:
container.fetchUserRecordID { (recordID, error) in
guard error == nil else { return }
guard let recordID = recordID else { return }
self.container.discoverUserInfo(withUserRecordID: recordID) { (info, fetchError) in
// use info.firstName and info.lastName however you need
print(info?.displayContact?.givenName)
}
}
I am getting the following message when running the print line: [LogFacilityCK] Got a user discovery progress callback with no user identity: { FetchInfo = ">"; }
The info variable is showing as nil when debugging.
Any thoughts?
Upvotes: 1
Views: 459
Reputation: 21
Here's how I got the users' name:
CKContainer.default().requestApplicationPermission(.userDiscoverability) { (status, error) in
CKContainer.default().fetchUserRecordID { (record, error) in
CKContainer.default().discoverUserIdentity(withUserRecordID: record!, completionHandler: { (userID, error) in
userName = (userID?.nameComponents?.givenName)! + " " + (userID?.nameComponents?.familyName)!
print("CK User Name: " + userName)
})
}
}
Upvotes: 0