xcode 如何将 ABAddressBookRef 用于 iPhone 应用程序?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5401659/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to use ABAddressBookRef for iPhone application?
提问by spaleja
I want reference of my address book in one of iPhone application. I have used below code. But its showing [people count] = 0.
我想在 iPhone 应用程序之一中参考我的地址簿。我使用了下面的代码。但它显示 [人数] = 0。
I have 3-4 contacts on my addressbook application still [people count] returns zero.
我的地址簿应用程序上有 3-4 个联系人,但 [人数统计] 返回零。
Is anything more, I am missing here?
还有什么吗,我在这里失踪了吗?
Code is:
代码是:
ABAddressBookRef addressBook = ABAddressBookCreate();
NSMutableArray *people = [[[(NSArray*)ABAddressBookCopyArrayOfAllPeople(addressBook) autorelease] mutableCopy]autorelease];
[people sortUsingFunction:(int (*)(id,id,void*)) ABPersonComparePeopleByName context:(void*)ABPersonGetSortOrdering()];
NSLog(@"count..%i",[people count]);
for(int i = 0 ; i < [people count]; i++){
ABRecordRef person = [people objectAtIndex:i];
//get phone no fill phone no into array
ABMultiValueRef multi = ABRecordCopyValue(person, kABPersonPhoneProperty);
if(multi!=NULL && ABMultiValueGetCount(multi)>0) {
NSLog(@"in value..");
}
else {
NSLog(@"no value");
}
}
Thank You
谢谢你
采纳答案by shannoga
try that -
试试看——
ABAddressBookRef addressBook = ABAddressBookCreate();
CFArrayRef people;
people = ABAddressBookCopyArrayOfAllPeople(HiByeGroup);
if (people){
CFArrayCreateMutableCopy(kCFAllocatorDefault,CFArrayGetCount(people),people);
NSInteger numberOfPersonsInAB=CFArrayGetCount(peopleMutable);
for (int i =0; i< numberOfPersonsInAB; i++) {
//your code
}
CFRelease(people);
UPdateAs Jamon Holmgren noted, this answer is old and ABAddressBookCreate()
is deprecated in iOS6. You need to use ABAddressBookCreateWithOptions()
instead.
GOOD LUCK
更新正如 Jamon Holmgren 所指出的,这个答案已经过时并且ABAddressBookCreate()
在 iOS6 中已被弃用。你需要ABAddressBookCreateWithOptions()
改用。祝你好运
回答by alloc_iNit
Just follow given code over here. A perfect example to interact with ABAddressBook.
只需按照此处的给定代码即可。与ABAddressBook交互的完美示例。