0

我正在尝试按名称在地址簿中搜索电话号码,

-(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);
}
4

1 回答 1

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);
于 2012-05-01T16:28:59.913 回答