How to display the SMS sending interface for iphone
1. First, add the framework to the project:
MessageUI. framework
2. Add the header file:
# Import <MessageUI/MessageUI. h>
3. Check whether there is a text message sending module on the machine. If not, a prompt is displayed.
// Determine whether SMS sending is supported <br/> BOOL bCanSendText = [MFMessageComposeViewController canSendText]; <br/> if (bCanSendText = NO) <br/> {<br/> UIAlertView * msgView = [[UIAlertView alloc] initWithTitle: @ "system prompt" message: @ "the machine does not support text message sending" delegate: nil cancelButtonTitle: @ "Confirm" otherButtonTitles: nil]; <br/> [msgView show]; <br/> [msgView release]; <br/> return; <br/>}
4. If you can send text messages, continue.
Class to implement the MFMessageComposeViewControllerDelegate proxy.
Then, implement the proxy method:-(void) messageComposeViewController :( MFMessageComposeViewController *) controller didFinishWithResult :( MessageComposeResult) result
-(Void) messageComposeViewController :( MFMessageComposeViewController *) controller didFinishWithResult :( MessageComposeResult) result <br/>{< br/> // Notifies users about errors associated with the interface <br/> switch (result) <br/>{< br/> case MessageComposeResultCancelled: <br/> NSLog (@ "Result: canceled"); <br/> break; <br/> case MessageComposeResultSent: <br/> NSLog (@ "Result: sent "); <br/> break; <br/> case MessageComposeResultFailed: <br/> NSLog (@" Result: Failed "); <br/> break; <br/> default: <br/> break; <br/>}< br/> [self dismissModalViewControllerAnimated: YES]; <br/>}
In this proxy method, you can see whether the final message sending result is canceled, successful, or failed. Finally, exit the modal view of the sent text message.
5. How to send text messages:
MFMessageComposeViewController * picker = [[MFMessageComposeViewController alloc] init]; <br/> picker. messageComposeDelegate = self; <br/> picker. navigationBar. tintColor = [UIColor blackColor]; <br/> NSString * nsbodyText = @ "Hello MyName Is HelloBoy"; <br/> picker. body = nsbodyText; </p> <p> NSMutableArray * tempArray = [NSMutableArray arrayWithCapacity: 0]; <br/> picker. recipients = [NSMutableArray arrayWithArray: tempArray]; </p> <p> [self presentModalViewController: picker animated: YES]; <br/> [picker release]; <br/>
The body attribute is the pre-edit of the content to be sent, and the recipients is the list of recipients of text messages.