Take the 2-minute tour ×
- (BOOL)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker shouldContinueAfterSelectingPerson:(ABRecordRef)person 
                            property:(ABPropertyID)property identifier:(ABMultiValueIdentifier)identifier {
if (property == kABPersonPhoneProperty) {
    ABMultiValueRef multiPhones = ABRecordCopyValue(person, kABPersonPhoneProperty);
    for(CFIndex i = 0; i < ABMultiValueGetCount(multiPhones); i++) {
        if(identifier == ABMultiValueGetIdentifierAtIndex (multiPhones, i)) {
            CFStringRef phoneNumberRef = ABMultiValueCopyValueAtIndex(multiPhones, i);
            NSString *phoneNumber = (NSString *) phoneNumberRef;
            RecipientContact *recipient = [[RecipientContact alloc] init];
            recipient.phoneNumber = [NSString stringWithFormat:@"%@", phoneNumber];
            recipient.name = nil;
            [recipients addObject:recipient];
            [recipient release];
            [phoneNumber release];
[self dismissModalViewControllerAnimated:YES];
[self _addRecipients];
return NO;

- (void)_addRecipients {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSString *names = [[NSString alloc] init];
for (RecipientContact *recipient in recipients) {
    names = [names stringByAppendingString:recipient.phoneNumber];
    names = [names stringByAppendingString:@";"];
contactsField.text = names;
[pool release];

I'm trying to use this code in my project ,but it'll crash when I go into the addressbook twice.I found when I CFRelease one of multiPhones and phoneNumberRef,it go well.But when I CFRelease both of them,the app will crash.
I have seen the Core Foundation Naming Conventions,it says "if a function name contains the word "Create" or "Copy", you own the object.",but why I release both of them my app crashed,thank you.

share|improve this question

1 Answer 1

The problem is you are using toll free bridging and then releasing the NSString

        NSString *phoneNumber = (NSString *) phoneNumberRef;
        [phoneNumber release]; //<-- this is like calling CFRelease(phoneNumberRef); again

Either call [phoneNumber retain] before CFRelease(phoneNumberRef); or just dont CFRelease the phoneNumberRef.

share|improve this answer
Thank you Joe ! I solved the matter. –  DJean Jun 22 '11 at 14:16
Your welcome remember to mark as accepted. –  Joe Jun 22 '11 at 14:17

Your Answer


