Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to get phone number of selected person in contacts

Tags:

iphone

I need to get phone number from contacts.

For that my code is

- (IBAction)contacts {

    NSLog(@"contacts clicked ");

    ABPeoplePickerNavigationController *peoplePickerController = [[ABPeoplePickerNavigationController alloc] init];
    peoplePickerController.peoplePickerDelegate = self;
    [self presentModalViewController:peoplePickerController animated:NO];
    [peoplePickerController release];

}
- (BOOL)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker
      shouldContinueAfterSelectingPerson:(ABRecordRef)person {
    NSString *number = (NSString *)ABRecordCopyValue(person, kABPersonPhoneProperty);

    NSLog(@" %@",number);
    return YES;
}

here it displays in console like this

ABMultiValueRef 0x740b680 with 1 value(s)
    0: _$!<Mobile>!$_ (0x7419880) - (929) 230-8622 (0x740b490)

Here (929) 230-8622 is mobile number,How can i get only mobile number.

After selecting contact i need to close this view controller.

For that i write code like this

[self dissmissModalViewControllerAnimated:YES];

But it shows waning that myclass may not respond to dissmissModalViewController.

How can i done that after selection i need to close this view controller.

can anyone pls help me.

Thank u in advance.

like image 915
Mahesh Babu Avatar asked Jan 10 '11 13:01

Mahesh Babu


2 Answers

I resolve my problem using By Adding this code.

- (BOOL)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker
      shouldContinueAfterSelectingPerson:(ABRecordRef)person
                                property:(ABPropertyID)property
                              identifier:(ABMultiValueIdentifier)identifier {
    if (property == kABPersonPhoneProperty) {
        ABMultiValueRef emails = ABRecordCopyValue(person, property);
        CFStringRef phonenumberselected = ABMultiValueCopyValueAtIndex(emails, identifier);
        CFStringRef emailLabelSelected = ABMultiValueCopyLabelAtIndex(emails, identifier);
        CFStringRef emailLabelSelectedLocalized = ABAddressBookCopyLocalizedLabel(ABMultiValueCopyLabelAtIndex(emails, identifier));
        NSLog(@"\n EmailValueSelected = %@ \n EmailLabelSelected = %@ \n \EmailLabeSelectedlLocalized = %@", phonenumberselected, emailLabelSelected, emailLabelSelectedLocalized);

        NSString *aNSString = (NSString *)phonenumberselected;



        [ self dismissModalViewControllerAnimated:YES ];
        return NO;
    }   
    return YES;
}

Hope this helpful who face problem like me.

like image 128
Mahesh Babu Avatar answered Oct 23 '22 04:10

Mahesh Babu


write below code in your

-(BOOL)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker shouldContinueAfterSelectingPerson:(ABRecordRef)person

{       

    ABMultiValueRef mul;
    mul=(NSString *) ABRecordCopyValue(person, kABPersonEmailProperty);
    int count= ABMultiValueGetCount(mul);
    NSString *name=(NSString *) ABMultiValueCopyValueAtIndex(mul,0);

}
like image 25
dks1725 Avatar answered Oct 23 '22 05:10

dks1725