如何从地址簿获取联系人到我们的本地应用程序
问题描述:
我使用下面的代码获取联系人进入我们的应用程序。如何从地址簿获取联系人到我们的本地应用程序
这个代码在设备工作正常,在模拟器allPeople获得零
任何事情,我忘记了一个请帮助我
if(addressBookCollection==nil) {
addressBookCollection = ABAddressBookCreate();
}
ABRecordRef source = ABAddressBookCopyDefaultSource(addressBookCollection);
CFArrayRef allPeople= ABAddressBookCopyArrayOfAllPeopleInSourceWithSortOrdering (addressBookCollection,source,1);
CFIndex nPeople = ABAddressBookGetPersonCount(addressBookCollection);
NSMutableArray* tempContactArray = [[NSMutableArray alloc] initWithCapacity:nPeople];
for(int i=0 ; i < nPeople; i++)
{
......
}
答
#import<AddressBook/AddressBook.h>
ABAddressBookRef addressBook = ABAddressBookCreate();
CFArrayRef all = ABAddressBookCopyArrayOfAllPeople(addressBook);
CFIndex n = ABAddressBookGetPersonCount(addressBook);
for(int i = 0 ; i < n ; i++)
{
ABRecordRef ref = CFArrayGetValueAtIndex(all, i);
ABMultiValueRef contactnumber = ABRecordCopyValue(ref, kABPersonPhoneProperty);
for(CFIndex j = 0; j < ABMultiValueGetCount(contactnumber); j++)
{
CFStringRef contactnumberRef = ABMultiValueCopyValueAtIndex(contactnumber, j);
NSString *contactnumberstr = (NSString *)contactnumberRef;
CFRelease(contactnumberRef); [self.contactnumberArray contactnumber];
[contactnumber release];
}
}
你会得到触点阵列“ self.contactnumberArray”。
享受!
对此有帮助吗? http://*.com/questions/3747844/get-a-list-of-all-contacts-on-ios –