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 ");
}