-5

I have used the following code but it not worked.

My code is:

MFMessageComposeViewController *controller = [[[MFMessageComposeViewController alloc] init] autorelease];
controller.body = @"Check out 'Invite Me' for iOS and be my friend here.";
controller.recipients = arrSelectedPhoneNumbers;
NSLog(@"%@",controller.recipients);
controller.messageComposeDelegate = self;
[self presentViewController:controller animated:YES completion:nil];
Cœur
  • 37,241
  • 25
  • 195
  • 267
Jeet
  • 13
  • 5
  • if([MFMessageComposeViewController canSendText]) { controller.body = @"Check out 'Invite Me' for iOS and be my friend here."; controller.recipients = arrSelectedPhoneNumbers; NSLog(@"%@",controller.recipients); controller.messageComposeDelegate = self; [self presentViewController:controller animated:YES completion:nil]; } – Jeet Jul 09 '13 at 06:06
  • Check out http://stackoverflow.com/questions/14532747/mfmessagecomposeviewcontroller-not-working ... You are missing many things here – NightFury Jul 09 '13 at 06:12
  • You must google before posting question on SO! – NightFury Jul 09 '13 at 06:13
  • hey i have used all the things but due to crietea of side it will not display..controller.recipients = arrSelectedPhoneNumbers is correct? – Jeet Jul 09 '13 at 06:25
  • arrSelectedPhoneNumbers is the nsmutable array of multiple no's, – Jeet Jul 09 '13 at 06:26

1 Answers1

1

Use following way :

// Add delegate in .h file

@interface ContactsViewController : UIViewController<MFMessageComposeViewControllerDelegate>

// Add this in your .m file

 MFMessageComposeViewController *picker = [[MFMessageComposeViewController alloc] init];
                if(picker) {
                    picker.messageComposeDelegate = self;
                    picker.recipients = [NSArray arrayWithObject:number];
                    picker.body = @"body content";
                    [self presentViewController:picker animated:NO completion:nil];
                    picker = nil;
                }
                NSLog(@"SMS fired");

    - (void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result {

            switch (result)
            {
                case MessageComposeResultCancelled:
                    NSLog(@"Result: canceled");
                    break;
                case MessageComposeResultSent:
                    NSLog(@"Result: sent");
                    break;
                case MessageComposeResultFailed:
                    NSLog(@"Result: failed");
                    break;
                default:
                    NSLog(@"Result: not sent");
                    break;
            }
            //[self dismissModalViewControllerAnimated:YES];
            [self dismissViewControllerAnimated:YES completion:nil];
        }
Divya Bhaloidiya
  • 5,018
  • 2
  • 25
  • 45