0

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);
}
Community
  • 1
  • 1
danny huang
  • 155
  • 9

1 Answers1

3

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);
unexpectedvalue
  • 6,079
  • 3
  • 38
  • 62