0

I have strange behavour of AddressBook framework. I'm creating and showing people picker controller this way:

ABPeoplePickerNavigationController *picker = [[ABPeoplePickerNavigationController alloc] init];
picker.peoplePickerDelegate = self;
NSArray *displayedItems = [NSArray arrayWithObjects:[NSNumber numberWithInt:kABPersonFirstNameProperty], [NSNumber numberWithInt:kABPersonLastNameProperty], nil];
picker.displayedProperties = displayedItems;
[self presentViewController: picker animated:YES completion: nil];

then in delegate I have the following:

- (BOOL)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker shouldContinueAfterSelectingPerson:(ABRecordRef)person
{
    myPersonRec = person;
    [self dismissViewControllerAnimated:YES completion: nil];
    return NO;
}

later when I try to access myPersonRec properties, I can read only first name and last name (which were displayed in people picker), all other properties are nil. If I change return value to YES, I'll get phone numbers and all stuff, but won't be able to get person's image anyway. What am I doing wrong?

dieworld
  • 1,090
  • 9
  • 9

1 Answers1

0

Problem source was found:

ABPerson object is not loaded into memory whole at once. It is loaded partially and new fields or image are loaded when needed, and to be loaded properly, this object should be tied to an exististing ABAddressBook instance. When I used person picker viewcontroller, it referenced to it's own ABAddressBook instance that was released after picker was dismissed, so I wasn't able to get any new data after viewcontroller dismissal (but entries which were loaded earlier still were accessible).

To solve this problem I've created an ABAddressBook shared instance in my model class singleton, and use it whenever I need. Since I'm only reading from address book, it should be fine solution.

So, picker creating code should look like this finally:

ABPeoplePickerNavigationController *picker = [[ABPeoplePickerNavigationController alloc] init];
picker.peoplePickerDelegate = self;
NSArray *displayedItems = [NSArray arrayWithObjects:[NSNumber numberWithInt:kABPersonFirstNameProperty], [NSNumber numberWithInt:kABPersonLastNameProperty], nil];
picker.displayedProperties = displayedItems;
picker.addressBook = [[MyModel instance] sharedAddressBookRef];
[self presentViewController: picker animated:YES completion: nil];
dieworld
  • 1,090
  • 9
  • 9