您好我需要在tableview中显示所有地址簿联系人。如果用户想要选择多个联系人删除那些选定的联系人。为此我没有找到任何解决方案,请帮助我。
答案 0 :(得分:2)
你可以试试这个:
您需要#import <AddressBookUI/AddressBookUI.h>
:
-(void) removeContactWithRecordsList:(CFArrayRef) selectedRecords_ {
ABAddressBookRef addressbook = ABAddressBookCreate();
if (selectedRecords_ != NULL)
{
int count = CFArrayGetCount(selectedRecords_);
for (int i = 0; i < count; ++i)
{
ABRecordRef contact = CFArrayGetValueAtIndex(selectedRecords_, i);
ABAddressBookRemoveRecord(addressbook, contact, nil);
}
}
ABAddressBookSave(addressbook, nil);
CFRelease(addressbook);
}
修改强>
示例:根据我的情况,我想删除所有联系人名称“Sample”
NSString *searchName = @"Sample";
ABAddressBookRef addressbook = ABAddressBookCreate();
CFStringRef nameRef = (__bridge CFStringRef) searchName;
CFArrayRef allSearchRecords = ABAddressBookCopyPeopleWithName(addressbook, nameRef);
[self removeContactWithRecordsList:allSearchRecords];