Ranga
Ranga

Reputation: 821

How to write code to pick the selected phone num address from phone book to send msg from my iphone application

I have implemented send sms code like this...

it's FINE but the problem is in picking the Number of the recipient .

in my code number is the value entered in a textfiled,

but i wan t to get the number from the phone book contacts.

How retrieve this any help please

ContactNUMBER = NumbertxtField.text

//Method for send sms button

-(IBAction)sendSMS:(id)sender
{
     MFMessageComposeViewController *controller = [[[MFMessageComposeViewController alloc] init] autorelease];
    if([MFMessageComposeViewController canSendText])
    {


           controller.recipients = [NSArray arrayWithObjects: ContactNUMBER, nil];



           controller.body = messageBody.text;
           controller.messageComposeDelegate = self;
           [self presentModalViewController:controller animated:YES];
        }
}

![enter image description here][1]

//Method for pick the contacts from phone book by click the DiscloserButton

-(IBAction)phoneBook_ DiscloserButton :(id)sender

{

}

//Message composer delegate method

- (void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result
{
    switch (result) {
        case MessageComposeResultCancelled:
            NSLog(@"Cancelled");
            break;

        case MessageComposeResultFailed:
        {
            UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Sharing our app" message:@"Unknown Error"
                                                           delegate:self cancelButtonTitle:@"Ok"otherButtonTitles: nil];
            [alert show];
            [alert release];
        }
            break;

        case MessageComposeResultSent:

            break;
        default:
            break;
    }

    [self dismissModalViewControllerAnimated:YES];
}

Upvotes: 0

Views: 222

Answers (1)

KAREEM MAHAMMED
KAREEM MAHAMMED

Reputation: 1695

For getting iPhone contacts Apple provide ABPeoplePickerViewController

Upvotes: 1

Related Questions