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 |
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
-
messageComposeDelegateproperty
Setting the Initial Message Information
-
recipientsproperty -
bodyproperty
Properties
body
The initial content of the message.
Availability
- Available in iOS 4.0 and later.
Declared In
MFMessageComposeViewController.hmessageComposeDelegate
The delegate to which message-related notifications should be sent.
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.
Declared In
MFMessageComposeViewController.hrecipients
An array of strings containing the initial recipients of the message.
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.hClass Methods
canSendText
Returns a Boolean value indicating whether the current device is capable of sending text messages.
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.hConstants
MessageComposeResult
These constants describe the result of the message composition interface.
enum MessageComposeResult {
MessageComposeResultCancelled,
MessageComposeResultSent,
MessageComposeResultFailed
};
typedef enum MessageComposeResult MessageComposeResult;
Constants
MessageComposeResultCancelledThe user canceled the composition.
Available in iOS 4.0 and later.
Declared in
MFMessageComposeViewController.h.MessageComposeResultSentThe user successfully queued or sent the message.
Available in iOS 4.0 and later.
Declared in
MFMessageComposeViewController.h.MessageComposeResultFailedThe 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.hMFMessageComposeViewControllerTextMessageAvailabilityKey
A userInfo dictionary key for the MFMessageComposeViewControllerTextMessageAvailabilityDidChangeNotification notification.
NSString *const MFMessageComposeViewControllerTextMessageAvailabilityKey;
Constants
MFMessageComposeViewControllerTextMessageAvailabilityKeyThe value of this key is an
NSNumberobject containing a Boolean value. This value matches the result of thecanSendTextclass method.Available in iOS 5.0 and later.
Declared in
MFMessageComposeViewController.h.
Notifications
MFMessageComposeViewControllerTextMessageAvailabilityDidChangeNotification
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
- Available in iOS 5.0 and later.
Declared In
MFMessageComposeViewController.h© 2011 Apple Inc. All Rights Reserved. (Last updated: 2011-10-12)