IOS development, calling, sending text messages, opening URLs, and sending text messages to ios

Source: Internet
Author: User

IOS development, calling, sending text messages, opening URLs, and sending text messages to ios

1. Call built-in mail

[[UIApplication sharedApplication] openURL: [NSURL URLWithString: @ "mailto: // admin@hzlzh.com"];

 

2. Call phone

[[UIApplication sharedApplication] openURL: [NSURL URLWithString: @ "tel: // 8008808888"];

 

3. Call SMS

[[UIApplication sharedApplication] openURL: [NSURL URLWithString: @ "sms: // 800888"];

 

4. Call the self-contained browser safari

[[UIApplication sharedApplication] openURL: [NSURL URLWithString: @ "http://www.hzlzh.com"];

 

You can call phone to pass the number. You can call SMS to set only the number and Cannot initialize the SMS content.

 

To transfer the content, you can do the following:

Add: MessageUI. framework

 

# Import <MessageUI/MFMessageComposeViewController. h>

 

Implement Proxy: MFMessageComposeViewControllerDelegate

 

 

 

Call the sendSMS Function

// Content, Recipient List

-(Void) sendSMS :( NSString *) bodyOfMessage recipientList :( NSArray *) recipients

{

 

MFMessageComposeViewController * controller = [[[MFMessageComposeViewController alloc] init] autorelease];

 

If ([MFMessageComposeViewController canSendText])

 

{

 

Controller. body = bodyOfMessage;

 

Controller. recipients = recipients;

 

Controller. messageComposeDelegate = self;

 

[Self presentModalViewController: controller animated: YES];

 

}

 

}

 

// Process the sent response results
-(Void) messageComposeViewController :( MFMessageComposeViewController *) controller didFinishWithResult :( MessageComposeResult) result
{
[Self dismissModalViewControllerAnimated: YES];
 
If (result = MessageComposeResultCancelled)
NSLog (@ "Message canceled ")
Else if (result = MessageComposeResultSent)
NSLog (@ "Message sent ")
Else
NSLog (@ "Message failed ")
}

 

 

The email is sent as follows:

Import # import <MessageUI/MFMailComposeViewController. h>

Implement Proxy: MFMailComposeViewControllerDelegate

 

// Send an email

-(Void) sendMail :( NSString *) subject content :( NSString *) content {

 

MFMailComposeViewController * controller = [[[MFMailComposeViewController alloc] init] autorelease];

 

If ([MFMailComposeViewController canSendMail])

 

{

 

[Controller setSubject: subject];

 

[Controller setMessageBody: content isHTML: NO];

 

Controller. mailComposeDelegate = self;

 

[Self presentModalViewController: controller animated: YES];

 

}

}

 

// Complete email processing

-(Void) mailComposeController :( MFMailComposeViewController *) controller didFinishWithResult :( MFMailComposeResult) result error :( NSError *) error {

 

[Self dismissModalViewControllerAnimated: YES];

 

If (result = MessageComposeResultCancelled)

NSLog (@ "Message canceled ");

Else if (result = MessageComposeResultSent)

NSLog (@ "Message sent ");

Else

NSLog (@ "Message failed ");

 

}

Related Article

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.