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?
Have you checked +[MFMessageComposeViewController canSendText]
?
From the MFMessageComposeViewController Class Reference,
Before presenting a message composition view, call the
canSendText
class method to ensure that the user’s device is appropriately configured. Do not attempt to present a message composition view if the canSendText method returns NO. If SMS delivery isn’t available, you can notify the user or simply disable the SMS features in your application.Starting in iOS 5, you can register to be notified of changes to the availability of text message sending by way of the
MFMessageComposeViewControllerTextMessageAvailabilityDidChangeNotification
notification.
Reasons it might be returning nil
:
Similarly, [[MFMailComposeViewController alloc] init]
returns nil
when no mail accounts are enabled (you can quickly test this by disabling accounts in Settings), but also shows a "No mail accounts configured" alert for you. MFMessageComposeViewController does not do this.