CNContactFormatter 需要哪些密钥?
Which keys do I need for CNContactFormatter?
我正在尝试使用新 CNContactFormatter
格式化联系人姓名。看起来,我没有获取所有需要的联系人姓名属性。
Terminating app due to uncaught exception 'CNPropertyNotFetchedException', reason: 'A property was not requested when contact was fetched.'
有人知道需要哪些吗?我尝试在其他一些人中获取以下内容,但没有成功:
CNContactNamePrefixKey,
CNContactGivenNameKey,
CNContactFamilyNameKey,
CNContactMiddleNameKey,
CNContactPreviousFamilyNameKey,
CNContactNameSuffixKey,
CNContactNicknameKey,
CNContactPhoneticGivenNameKey,
CNContactPhoneticMiddleNameKey,
CNContactPhoneticFamilyNameKey,
CNContactOrganizationNameKey,
CNContactDepartmentNameKey,
CNContactJobTitleKey,
CNContactFomatter Class Reference nor the fetching method's documentation 都没有提供任何线索。
谢谢!
我在 WWDC Session 223(从幻灯片 74 开始)中找到了它,当我遇到同样的问题时它对我有用。在联系人选择调用中使用 CNContactFormatter.descriptorForRequiredKeysForStyle...。示例:
let contactStore = CNContactStore()
let predicate = CNContact.predicateForContactsMatchingName("John")
let foundContacts = try contactStore.unifiedContactsMatchingPredicate(predicate, keysToFetch: [CNContactFormatter.descriptorForRequiredKeysForStyle(.FullName)]
for contact in foundContacts {
print(CNContactFormatter.stringFromContact(contact, style: .FullName))
}
class func descriptorForRequiredKeys()
用于获取从联系人创建 vCard 数据所需的所有联系人密钥。
https://developer.apple.com/reference/contacts/cncontactvcardserialization
示例:
let containerResults = try contactStore.unifiedContacts(matching: fetchPredicate, keysToFetch:[CNContactVCardSerialization.descriptorForRequiredKeys()])
我正在尝试使用新 CNContactFormatter
格式化联系人姓名。看起来,我没有获取所有需要的联系人姓名属性。
Terminating app due to uncaught exception 'CNPropertyNotFetchedException', reason: 'A property was not requested when contact was fetched.'
有人知道需要哪些吗?我尝试在其他一些人中获取以下内容,但没有成功:
CNContactNamePrefixKey,
CNContactGivenNameKey,
CNContactFamilyNameKey,
CNContactMiddleNameKey,
CNContactPreviousFamilyNameKey,
CNContactNameSuffixKey,
CNContactNicknameKey,
CNContactPhoneticGivenNameKey,
CNContactPhoneticMiddleNameKey,
CNContactPhoneticFamilyNameKey,
CNContactOrganizationNameKey,
CNContactDepartmentNameKey,
CNContactJobTitleKey,
CNContactFomatter Class Reference nor the fetching method's documentation 都没有提供任何线索。
谢谢!
我在 WWDC Session 223(从幻灯片 74 开始)中找到了它,当我遇到同样的问题时它对我有用。在联系人选择调用中使用 CNContactFormatter.descriptorForRequiredKeysForStyle...。示例:
let contactStore = CNContactStore()
let predicate = CNContact.predicateForContactsMatchingName("John")
let foundContacts = try contactStore.unifiedContactsMatchingPredicate(predicate, keysToFetch: [CNContactFormatter.descriptorForRequiredKeysForStyle(.FullName)]
for contact in foundContacts {
print(CNContactFormatter.stringFromContact(contact, style: .FullName))
}
class func descriptorForRequiredKeys()
用于获取从联系人创建 vCard 数据所需的所有联系人密钥。
https://developer.apple.com/reference/contacts/cncontactvcardserialization
示例:
let containerResults = try contactStore.unifiedContacts(matching: fetchPredicate, keysToFetch:[CNContactVCardSerialization.descriptorForRequiredKeys()])