如何从通讯录获取联系到我们的本机应用程序 [英] how to get contacts in to our native application from Addressbook
本文介绍了如何从通讯录获取联系到我们的本机应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用下面的代码来联系我们的应用程序.
i used below code for getting contacts in to our application.
此代码在设备 allPeople 设为零的模拟器中正常运行
this code is working fine in simulator in device allPeople getting Zero
我忘记了请帮助我的任何事情
any thing i forgot that one pls help me
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"数组中的联系人.
you will get the contacts in array of "self.contactnumberArray".
享受!
这篇关于如何从通讯录获取联系到我们的本机应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文