How to display the SMS sending interface for iphone

Source: Internet
Author: User

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.

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.