Text Message
The MFMessageComposeViewController class is a UINavigationController subclass. Before using this class to present a view, call canSendText; if the result is NO, go no further. The user has no option to save an SMS message as a draft, so even if this device sometimes can send text, there’s no point proceeding if the device can’t send text now. However, you can register for the MFMessageComposeViewControllerTextMessageAvailabilityDidChangeNotification in the hope that the device might later be able to send text; if the notification arrives, check its MFMessageComposeViewControllerTextMessageAvailabilityKey.
To use MFMessageComposeViewController, instantiate the class, give it a messageComposeDelegate, configure it as desired through the recipients (phone number strings) and body properties, and show it as a presented view controller. The user can later alter your preset configurations, at which time the message details will be out of your hands.
The delegate (MFMessageComposeViewControllerDelegate) will receive the message messageComposeViewController:didFinishWithResult: with a description of the user’s final action, which might be any of these:
-
MessageComposeResultCancelled -
MessageComposeResultSent -
MessageComposeResultFailed
Dismissing the presented view is up to you, in the delegate method.
Here’s a minimal example:
- (IBAction)doMessage:(id)sender { BOOL ok = [MFMessageComposeViewController canSendText]; if (!ok) return; MFMessageComposeViewController* vc = [MFMessageComposeViewController ...Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access