O'Reilly logo

Programming iOS 4 by Matt Neuburg

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 33. Mail

Your app can present interface allowing the user to edit and send a mail message (and, starting in iOS 4, an SMS message). Two view controller classes are provided by the Message UI framework; your app will link to MessageUI.framework and import <MessageUI/MessageUI.h>. The classes are:

MFMailComposeViewController
Allows composition and sending of a mail message.
MFMessageComposeViewController
Allows composition and sending of an SMS message.

Mail Message

The MFMailComposeViewController class, a UINavigationController, allows the user to edit a mail message. The user can attempt to send the message there and then or can cancel but save a draft, or can cancel completely. Before using this class to present a view, call canSendMail; if the result is NO, go no further. A negative result means that the device is not configured for sending mail. A positive result does not mean that the device is connected to the network and can send mail right now, only that sending mail is generally possible with this device.

To use MFMailComposeViewController, instantiate it, provide a mailComposeDelegate (not delegate), and configure the message to any desired extent. The user can alter your preset configurations. Configuration methods are:

  • setSubject:
  • setToRecipients:
  • setCcRecipients:
  • setBccRecipients:
  • setMessageBody:isHTML:
  • addAttachmentData:mimeType:fileName:

The delegate method mailComposeController:didFinishWithResult:error: is called with the user’s final action, which ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required