Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CloudKit, retrieve user information, such as first name on sign up

Tags:

swift

cloudkit

During SignUp on my app, I want to retrieve information, such as first name, from iCloud,I then want to store this in my own cloud kit database. How do I access user information from iCloud, without having to ask the user themselves for these relevant fields?

like image 457
user4174219 Avatar asked Oct 21 '25 13:10

user4174219


1 Answers

I was able to get it working with this in XCode 8 iOS 10 beta 2:

CKContainer.default().requestApplicationPermission(.userDiscoverability) { (status, error) in
            CKContainer.default().fetchUserRecordID { (record, error) in
                CKContainer.default().discoverUserIdentity(withUserRecordID: record!, completionHandler: { (userID, error) in
                    print(userID?.hasiCloudAccount)
                    print(userID?.lookupInfo?.phoneNumber)
                    print(userID?.lookupInfo?.emailAddress)
                    print((userID?.nameComponents?.givenName)! + " " + (userID?.nameComponents?.familyName)!)
                })
            }
        }
like image 83
Wesley Filleman Avatar answered Oct 24 '25 06:10

Wesley Filleman