我正在尝试获取CloudKit用户的名字和姓氏。
以下是代码:
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)
}
}
运行打印行时,我收到以下消息 :[LogFacilityCK]获得了没有用户标识的用户发现进度回调:{ FetchInfo =“>”; }
调试时,info变量显示为nil。
有什么想法吗?
答案 0 :(得分:0)
以下是我获得用户名称的方式:
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)
})
}
}