2 Replies
      Latest reply on Aug 29, 2019 4:36 AM by sumair.aswani
      wfilleman Level 1 Level 1 (0 points)

        Hi Everyone,

         

        I'm using the latest XCode 8 Beta 2, and I'm unable to get the current iCloud user's name. Here's the code snippit:

         

        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)!)
               })
        }
        

         

        record returned in line 1 is a real record. I think this shows that the app is connected to CloudKit and a container correctly.

        userID in line 2 is nil as well as error is nil.

         

        Has anyone been able to get the current user's iCloud name in XCode 8 iOS 10 Beta 2?

         

        Wes

        • Re: Get the name of the current CloudKit user
          wfilleman Level 1 Level 1 (0 points)

          Update:

           

          Looks like you need to ask for permission first:

           

          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)!)
                          })
                      }
                  }