这个ABaddressBook NSLog是什么意思?

时间:2012-05-01 16:26:27

标签: objective-c ios xcode nslog abaddressbook

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

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

1 个答案:

答案 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);