Question

I'm trying to take phone number from the Contacts on the iPhone. I implemented the

-(BOOL)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker shouldContinueAfterSelectingPerson:(ABRecordRef)person property:(ABPropertyID)property identifier:(ABMultiValueIdentifier)identifier

from the ABPeoplePickerNavigationControllerDelegate

In this method there is this code and it works:

NSString *firstName = (NSString *)CFBridgingRelease(ABRecordCopyValue(person, kABPersonFirstNameProperty));
    NSLog(@"First Name ---> %@" ,firstName);

    NSString *secondName = (NSString *)CFBridgingRelease(ABRecordCopyValue(person, kABPersonLastNameProperty));
    NSLog(@"Last name ---> %@" ,secondName);

but now I need to take also the phone number selected from the user. I have tried with this but it doesn't work for me:

NSString *numberSelected = (NSString *)CFBridgingRelease(ABRecordCopyValue(person, property));

this give me a strange value like this:

ABMultiValueRef 0xa36e990 with 1 value(s)
    0: _$!<Mobile>!$_ (0xa36ee50) - (123) 456-7890 (0xa36ee70)

Then I tried with this but also this doesn't work:

ABMutableMultiValueRef multi = ABRecordCopyValue(person, property);
    CFStringRef phone = ABMultiValueCopyLabelAtIndex(multi, identifier);
    NSLog(@"Number Selected ---> %@" ,(NSString *)CFBridgingRelease(phone));
    CFRelease(phone);

    NSLog(@"Number Selected --> %@" ,numberSelected);

The string displayed is only:

_$!<Mobile>!$_

Now I don't know what to do... can you help me?

Thanks!

Was it helpful?

Solution

Try with is :

    CFStringRef cfnumber;
    ABMultiValueRef numbers = ABRecordCopyValue(person, kABPersonPhoneProperty); 
    for(CFIndex i = 0; i < ABMultiValueGetCount(numbers); i++) 
    {
        if(identifier == ABMultiValueGetIdentifierAtIndex (numbers, i)) 
        { 
            //if tapped number identifier is the same as identifier number tapped
            cfnumber = ABMultiValueCopyValueAtIndex(numbers, i); // copy the number to CFSTRING number
        }
    }        
    NSString *number = [NSString stringWithFormat:@"%@",cfnumber];
    CFRelease(cfnumber); 
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top