danny huang
danny huang

Reputation: 155

what does this ABaddressBook NSLog Mean?

I am trying to search the AddressBook for Phone Numbers by name,

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

and i get a log of this

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>"
)

I dont know what the string in the middle mean, did it return correctly??

EDIT

for(NSString *name in savedPeople){
    CFArrayRef people = ABAddressBookCopyPeopleWithName(addressBook, (CFStringRef)name);
    CFTypeRef phoneProperty = ABRecordCopyValue((ABRecordRef)people, kABPersonPhoneProperty);
    NSLog(@"%@",phoneProperty);
}

Upvotes: 0

Views: 572

Answers (1)

unexpectedvalue
unexpectedvalue

Reputation: 6139

Yes it is an ABPerson record.

Your code is doing what you want but is written very badly, [[[NSMutableArray alloc]initWithArray:savedPeople]objectAtIndex:i]; is a NSString, not an array.

for(NSString *name in savedPeople)
    CFArrayRef people = ABAddressBookCopyPeopleWithName(addressBook, (CFStringRef)name);

To extract values from ABPerson check out the documentation. For example:

CFTypeRef phoneProperty = ABRecordCopyValue((ABRecordRef)people, kABPersonPhoneProperty);

Upvotes: 3

Related Questions