views:

281

answers:

1

In my application, MFMailComposeViewController works fine but creating a new instance of MFMessageComposeViewController fails.

Here is the code for both:

-( IBAction)sendSMS: (id)sender
{
 MFMessageComposeViewController *picker = [[[MFMessageComposeViewController alloc] init] autorelease];
 picker.messageComposeDelegate = self;

 NSArray *toRecipients = [NSArray arrayWithObject: cell.currentTitle ]; 

 picker.recipients = toRecipients;

 [self presentModalViewController:picker animated:YES];
}

-( IBAction)sendEmail: (id)sender
{
 MFMailComposeViewController *picker = [[[MFMailComposeViewController alloc] init] autorelease];
 picker.mailComposeDelegate = self;

 NSArray *toRecipients = [NSArray arrayWithObject: email.currentTitle ]; 

 [picker setToRecipients:toRecipients];

 [self presentModalViewController:picker animated:YES];
}

Its seemingly obvious that everything is linking correctly because the email view controller works fine. Is there something I am missing maybe configuration wise?

+3  A: 

Have you checked +[MFMessageComposeViewController canSendText]? From the docs,

Before using this class, you must always check to see if the current device is configured to send SMS messages by calling the canSendText class method. If the user’s device is not set up for the delivery of SMS messages, you can notify the user or simply disable the SMS features in your application. You should not attempt to use this interface if the canSendText method returns NO.

Other reasons it might not work:

  • No SIM card?
  • Device isn't running iOS 4.
  • Device is an iPod Touch/iPad.
  • "Device" is actually the simulator.
tc.
Excellent, thanks. I probably should have been more clear in that the issue arises using the simulator, which obviously doesn't have SMS capability.
Lee
If there is no SIM card, the app exits. why? it just gives a pop up message "no sim card present". it event send a SMS sent result to the delegate method. then exits. is there any way to prevent it from exiting?
karim
Have you checked the console for messages? Does it crash or exit "normally"? Is there a crash log? Does attaching a debugger help?
tc.