一、ABRecord 联系人信息
// 信息 id,具有唯一性
ABRecordGetRecordID(<#T##record: ABRecord!##ABRecord!#>)
// 信息 类型,可以是 kABPersonType 和 kABGroupType
ABRecordGetRecordType(<#T##record: ABRecord!##ABRecord!#>)
// 获取信息内部某条数据
ABRecordCopyValue(<#T##record: ABRecord!##ABRecord!#>, <#T##property: ABPropertyID##ABPropertyID#>)
// 全名
ABRecordCopyCompositeName(<#T##record: ABRecord!##ABRecord!#>)
// 修改信息
ABRecordSetValue(<#T##record: ABRecord!##ABRecord!#>, kABPersonFirstNameProperty, <#T##value: CFTypeRef!##CFTypeRef!#>, <#T##error: UnsafeMutablePointer<Unmanaged<CFError>?>!##UnsafeMutablePointer<Unmanaged<CFError>?>!#>)
// 移除信息
ABRecordRemoveValue(<#T##record: ABRecord!##ABRecord!#>, kABPersonFirstNameProperty, <#T##error: UnsafeMutablePointer<Unmanaged<CFError>?>!##UnsafeMutablePointer<Unmanaged<CFError>?>!#>)
二、ABPerson
guard let aRecordRef = ABPersonCreate() else {
return
}
ABPersonCreateInSource(aRecordRef as ABRecord)
ABPersonCopySource(aRecordRef as ABRecord)
guard let aRecordRef = ABPersonCreate() else {
return
}
ABPersonCreateInSource(aRecordRef as ABRecord)
ABPersonCopySource(aRecordRef as ABRecord)
if let addressBook = ABAddressBookCreate() {
// 获取所有的联系人数量
ABAddressBookGetPersonCount(addressBook as ABAddressBook)
// 根据 ID 获取联系人 记录
ABAddressBookGetPersonWithRecordID(addressBook as ABAddressBook, 123)
// 获取所有联系人 记录
ABAddressBookCopyArrayOfAllPeople(addressBook as ABAddressBook)
// 新排序 的所有 联系人 记录
ABAddressBookCopyArrayOfAllPeopleInSourceWithSortOrdering(addressBook as ABAddressBook, aRecordRef as ABRecord, ABPersonSortOrdering(kABPersonSortByFirstName))
// 根据 名 搜索联系人
ABAddressBookCopyPeopleWithName(addressBook as ABAddressBook, "123" as CFString)
}
if let addressBook = ABAddressBookCreate() {
// 获取所有联系人 记录
let peopleArray = ABAddressBookCopyArrayOfAllPeople(addressBook as ABAddressBook)
// 根据上面获取的联系人 记录数组获取某个联系人
if let person = CFArrayGetValueAtIndex(peopleArray as! CFArray, 0) as? ABRecord {
let lastName = ABRecordCopyValue(person, kABPersonLastNameProperty)
if let phones = ABRecordCopyValue(person, kABPersonPhoneProperty) as? ABMultiValue {
let phoneCount = ABMultiValueGetCount(phones)
for i in 0 ..< phoneCount {
let phoneLabel = ABMultiValueCopyLabelAtIndex(phones, i)
let phoneValue = ABMultiValueCopyValueAtIndex(phones, i)
}
}
}
}
if let addressBook = ABAddressBookCreate() {
// 获取所有联系人 记录
let peopleArray = ABAddressBookCopyArrayOfAllPeople(addressBook as ABAddressBook)
// 根据上面获取的联系人 记录数组获取某个联系人
if let person = CFArrayGetValueAtIndex(peopleArray as! CFArray, 0) as? ABRecord {
if ABPersonHasImageData(person) {
let head = ABPersonCopyImageData(person)
let headOption = ABPersonCopyImageDataWithFormat(person, kABPersonImageFormatThumbnail)
if ABPersonRemoveImageData(person, nil) {
// 移除头像成功
}
if ABPersonSetImageData(person, headOption as! CFData, nil) {
// 设置头像成功
}
}
}
}
if let addressBook = ABAddressBookCreate() {
// 获取所有联系人 记录
let peopleArray = ABAddressBookCopyArrayOfAllPeople(addressBook as ABAddressBook)
// 联系人记录 转 名片数据
let cd = ABPersonCreateVCardRepresentationWithPeople(peopleArray as! CFArray)
let ca = ABPersonCreatePeopleInSourceWithVCardRepresentation(nil, cd as! CFData)
}
if let addressBook = ABAddressBookCreate() {
ABAddressBookSave(addressBook as ABAddressBook, nil)
}
if let addressBook = ABAddressBookCreate() {
// 获取所有联系人 记录
let peopleArray = ABAddressBookCopyArrayOfAllPeople(addressBook as ABAddressBook)
// 根据上面获取的联系人 记录数组获取某个联系人
if let person = CFArrayGetValueAtIndex(peopleArray as! CFArray, 0) as? ABRecord {
ABAddressBookAddRecord(addressBook as ABAddressBook, person, nil)
ABAddressBookRemoveRecord(addressBook as ABAddressBook, person, nil)
}
}
网友评论