MFMessageComposeViewController Class Reference

Inherits from
Conforms to
Framework
/System/Library/Frameworks/MessageUI.framework
Availability
Available in iOS 4.0 and later.
Companion guide
Declared in
MFMessageComposeViewController.h
Related sample code

Overview

The MFMessageComposeViewController class provides a standard system user interface for composing SMS (Short Message Service) text messages. Use this class to configure the initial recipients and body of the message, if desired, and to configure a delegate object to respond to the final result of the user’s action—whether they chose to cancel or send the message. After configuring initial values, present the view controller modally using the presentModalViewController:animated: method. When done, dismiss it using the dismissModalViewControllerAnimated: method.

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.

Your delegate object is responsible for dismissing the message compose view controller in its messageComposeViewController:didFinishWithResult: method. For more information about implementing this method, see MFMessageComposeViewControllerDelegate Protocol Reference.

Tasks

Determining If Message Composition Is Available

Accessing the Delegate

Setting the Initial Message Information

Properties

body

The initial content of the message.

@property (nonatomic,copy) NSString *body
Availability
  • Available in iOS 4.0 and later.
Declared In
MFMessageComposeViewController.h

messageComposeDelegate

The delegate to which message-related notifications should be sent.

@property (nonatomic,assign) id<MFMessageComposeViewControllerDelegate> messageComposeDelegate
Discussion

When the user taps a button to send or cancel the message, your delegate is notified and should respond by dismissing the message composition interface. For more information about implementing the methods of your delegate object, see MFMessageComposeViewControllerDelegate Protocol Reference.

Availability
  • Available in iOS 4.0 and later.
Related Sample Code
Declared In
MFMessageComposeViewController.h

recipients

An array of strings containing the initial recipients of the message.

@property (nonatomic,copy) NSArray *recipients
Discussion

Each string in the array should contain the phone number of the intended recipient.

Availability
  • Available in iOS 4.0 and later.
Declared In
MFMessageComposeViewController.h

Class Methods

canSendText

Returns a Boolean value indicating whether the current device is capable of sending text messages.

+ (BOOL)canSendText
Return Value

YES if the device can send text messages or NO if it cannot.

Discussion

Always call this method before attempting to present the message compose view controller. A device may be unable to send messages if it does not support text message or if it is not currently configured to send messages. This method applies only to the ability to send text messages. Sending multimedia messages with this class is not supported.

in iOS 5.0 or later, you should register as an observer of the MFMessageComposeViewControllerTextMessageAvailabilityDidChangeNotification notification to be notified of changes in the availability of sending text messages.

Availability
  • Available in iOS 4.0 and later.
Declared In
MFMessageComposeViewController.h

Constants

MessageComposeResult

These constants describe the result of the message composition interface.

enum MessageComposeResult {
   MessageComposeResultCancelled,
   MessageComposeResultSent,
   MessageComposeResultFailed
};
typedef enum MessageComposeResult MessageComposeResult;
Constants
MessageComposeResultCancelled

The user canceled the composition.

Available in iOS 4.0 and later.

Declared in MFMessageComposeViewController.h.

MessageComposeResultSent

The user successfully queued or sent the message.

Available in iOS 4.0 and later.

Declared in MFMessageComposeViewController.h.

MessageComposeResultFailed

The user’s attempt to save or send the message was unsuccessful.

Available in iOS 4.0 and later.

Declared in MFMessageComposeViewController.h.

Availability
  • Available in iOS 4.0 and later.
Declared In
MFMessageComposeViewController.h

MFMessageComposeViewControllerTextMessageAvailabilityKey

A userInfo dictionary key for the MFMessageComposeViewControllerTextMessageAvailabilityDidChangeNotification notification.

NSString *const MFMessageComposeViewControllerTextMessageAvailabilityKey;
Constants
MFMessageComposeViewControllerTextMessageAvailabilityKey

The value of this key is an NSNumber object containing a Boolean value. This value matches the result of the canSendText class method.

Available in iOS 5.0 and later.

Declared in MFMessageComposeViewController.h.

Notifications

MFMessageComposeViewControllerTextMessageAvailabilityDidChangeNotification

Posted when the value returned by the canSendText class method has changed.

Upon receiving this notification, query its userInfo dictionary with the MFMessageComposeViewControllerTextMessageAvailabilityKey key. If the availability of text message sending has changed, your app should invalidate caches and update its user interface as appropriate.

Availability
Declared In
MFMessageComposeViewController.h

Did this document help you? Yes It's good, but... Not helpful...