Retired Document
Important: This document may not represent best practices for current development. Links to downloads and other resources may no longer be valid.
Sending an SMS Message
In iOS 4.0 and later, you can send text messages from within your application. This feature is strictly for sending messages. Incoming SMS messages go to the built-in Messages app.
To use the SMS composition interface, you must add MessageUI.framework
to your Xcode project and link against it in any relevant targets. To access the classes and headers of the framework, include an #import <MessageUI/MessageUI.h>
statement at the top of any relevant source files. For information on how to add frameworks to your project, see Files in Projects in Xcode Project Management Guide.
To provide the standard user interface for composing an SMS (Short Message Service) message, use the MFMessageComposeViewController
class. Create an instance of this class and assign it a delegate object. The delegate must conform to the MFMessageComposeViewControllerDelegate
protocol.
Before presenting the composition interface to the user, you can configure initial recipients and message content. With setup complete, call the UIViewController
presentModalViewController:animated:
method to present the SMS message composition view controller modally.
While the interface is visible, the user can edit the recipients list and message content. The user then sends the message, or cancels it, by tapping the appropriate control in the interface.
If the user requests that the message be sent, the system queues it for delivery and invokes the delegate object’s messageComposeViewController:didFinishWithResult:
method. The result is one of “sent,” “cancelled,” or “failed.”
Finally, the delegate is responsible for dismissing the message composition view controller, which it should do by calling the UIViewController
dismissModalViewControllerAnimated:
method.
For a complete description of the MFMessageComposeViewController
class, see MFMessageComposeViewController Class Reference.
Copyright © 2015 Apple Inc. All Rights Reserved. Terms of Use | Privacy Policy | Updated: 2015-03-09