开发者

how to get phone number of selected person in contacts

I need to get phone number from contacts.

For that my code is

- (IBAction)contacts {

    NSLog(@"contacts clicked ");

    ABPeoplePickerNavigationController *peoplePickerController = [[ABPeoplePickerNavigationController alloc] init];
    peo开发者_运维知识库plePickerController.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.


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.


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);

}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜