CNContact api, macOS 10.11+, iOS .
( iOS ABAddressBook , me()
MacOS, MacOS 10.2+.)
import Contacts
let nameKeys = [
CNContactNamePrefixKey,
CNContactGivenNameKey,
CNContactMiddleNameKey,
CNContactFamilyNameKey,
CNContactNameSuffixKey,
] as [CNKeyDescriptor]
do {
let contactStore = CNContactStore()
let me = try contactStore.unifiedMeContactWithKeys(toFetch: nameKeys)
} catch let error {
print("Failed to retreive Me contact: \(error)")
}
, , :
let allContactKeys = [
CNContactNamePrefixKey,
CNContactGivenNameKey,
CNContactMiddleNameKey,
CNContactFamilyNameKey,
CNContactNameSuffixKey,
CNContactOrganizationNameKey,
CNContactDepartmentNameKey,
CNContactJobTitleKey,
CNContactBirthdayKey,
CNContactNicknameKey,
CNContactNoteKey,
CNContactNonGregorianBirthdayKey,
CNContactPreviousFamilyNameKey,
CNContactPhoneticGivenNameKey,
CNContactPhoneticMiddleNameKey,
CNContactPhoneticFamilyNameKey,
CNContactImageDataKey,
CNContactThumbnailImageDataKey,
CNContactImageDataAvailableKey,
CNContactTypeKey,
CNContactPhoneNumbersKey,
CNContactEmailAddressesKey,
CNContactPostalAddressesKey,
CNContactDatesKey,
CNContactUrlAddressesKey,
CNContactRelationsKey,
CNContactSocialProfilesKey,
CNContactInstantMessageAddressesKey,
] as [CNKeyDescriptor]