我正在尝试按名称在地址簿中搜索电话号码
-(void)textMessage{
ABAddressBookRef addressBook = ABAddressBookCreate();
NSMutableArray *array;
for(int i = 0;i<[savedPeople count];i++){
array = [[[NSMutableArray alloc]initWithArray:savedPeople]objectAtIndex:i];
CFArrayRef people = ABAddressBookCopyPeopleWithName(addressBook, (CFStringRef)array);
NSLog(@"%@",people);
}
}
我得到了这个
的日志2012-05-01 09:22:31.688 UpOut[5829:15803] (
"<CPRecord: 0x84edf90 ABPerson>"
)
2012-05-01 09:22:31.694 UpOut[5829:15803] (
"<CPRecord: 0x84ee1c0 ABPerson>"
)
我不知道中间的字符串是什么意思,它是否正确返回?
for(NSString *name in savedPeople){
CFArrayRef people = ABAddressBookCopyPeopleWithName(addressBook, (CFStringRef)name);
CFTypeRef phoneProperty = ABRecordCopyValue((ABRecordRef)people, kABPersonPhoneProperty);
NSLog(@"%@",phoneProperty);
}
答案 0 :(得分:3)
是的,它是ABPerson记录。
您的代码正在执行您想要的操作,但编写得非常糟糕,[[[NSMutableArray alloc]initWithArray:savedPeople]objectAtIndex:i];
是NSString,而不是数组。
for(NSString *name in savedPeople)
CFArrayRef people = ABAddressBookCopyPeopleWithName(addressBook, (CFStringRef)name);
要从ABPerson
中提取值,请查看文档。例如:
CFTypeRef phoneProperty = ABRecordCopyValue((ABRecordRef)people, kABPersonPhoneProperty);