ios-How to send SMS, e-mails, and phone calls to app integration

Source: Internet
Author: User

1. Send SMS         
To achieve the function of the call, the main two methods, the following are the advantages and disadvantages of their respective.

1.1. Texting (1)--url      
Direct dialing, and will remain in the call log when the dial is completed

A, Method:
Nsurl *url = [Nsurl urlwithstring:@ "sms://10010"];

[[UIApplication sharedapplication] openurl:url];

B, Advantages:
– Simple
C, Disadvantages:
– SMS content cannot be specified and cannot be automatically returned to the original application

1.2 Texting (2)--messageui frame       
If you are customizing a text message, you need to use a frame messageui.

Advantages

A. Get back from the app

B. Can be many people

C. You can customize the message, the message supports HTML format

and if in the Apple system, if each other's phones are iOS devices, and opened the IMessage function, the text between each other is to take the network channel, and not take the operator's channel!

-(void) msg2{//  determine if the user device can send SMS if (!  [Mfmessagecomposeviewcontroller Cansendtext]) {return;}

1. Instantiate a controller

Mfmessagecomposeviewcontroller *controller = [[ Mfmessagecomposeviewcontroller alloc] init];

//2. Set SMS content   
//1) recipient


//2) SMS content


//3) Set proxy

3. Display SMS Controller
[Self Presentviewcontroller:controller animated:yes completion:nil];
}

Remember to send a message remember to call the Proxy method close the window


#pragma mark SMS Controller proxy method
/**
SMS Send results

messagecomposeresultcancelled, Cancel
messagecomposeresultsent, send
messagecomposeresultfailed Failure
*/
-(void) Messagecomposeviewcontroller: (Mfmessagecomposeviewcontroller *) controller didfinishwithresult: ( Messagecomposeresult) Result
{
NSLog (@ "%d", result);

//In Object-oriented program development, there is a principle, who applies, who releases!
//* * * This method also works because the system sends a shutdown message to self
//[controller Dismissviewcontrolleranimated:yes Completion:nil];

//should use this!!!
[self dismissviewcontrolleranimated:yes completion:nil];
}

2. Send an email    

-(void) SendMail
{
//1. First determine if you can send mail
if (![ Mfmailcomposeviewcontroller Cansendmail]) {
//Prompt user to set up mailbox
return;
}

//2. Instantiate the mail controller and prepare to send mail
Mfmailcomposeviewcontroller *controller = [[Mfmailcomposeviewcontroller alloc] init];

//1) Working report on theme XXX
[Controller setsubject:@ "My work Report"];
//2) Recipient
[Controller settorecipients:@[@ "[email protected]"];

//3) cc CC
///4) BCC secret Send (secretly tell, make a small report)
//5) Text
[Controller setmessagebody:@] This is my <font color=\ "blue\" > Work report </font>, please review! <br/>p.s. Is my head bull x? [Ishtml:yes];

//6) Accessories
UIImage *image = [UIImage imagenamed:@ "Avatar 1.png"];
NSData *imagedata = uiimagepngrepresentation (image);
//1> binary data for attachments
//2> MIMEType use what application to open attachments
//3> The name of the file that the recipient sees when receiving
//Can add multiple attachments
[Controller Addattachmentdata:imagedata mimetype:@ "image/png" filename:@ "Avatar. png"];

///7) Set up proxy
[Controller setmailcomposedelegate:self];

//Display Controller
[self Presentviewcontroller:controller animated:yes completion:nil];
}

Also remember to send out messages remember to call the proxy method to close the window


#pragma mark-mail agent Method
/**
mfmailcomposeresultcancelled, Cancel
mfmailcomposeresultsaved, saving messages
Mfmailcomposeresultsent, has been sent
mfmailcomposeresultfailed Send failed
*/
-(void) Mailcomposecontroller: (Mfmailcomposeviewcontroller *) controller didfinishwithresult: ( Mfmailcomposeresult) Result Error: (NSERROR *) Error
{
//Prompt user according to different status
NSLog (@ "%d", result);

[self dismissviewcontrolleranimated:yes completion:nil];
}

3. Call
There are three ways to make calls, and the pros and cons are different.

3.1. Call not back reference

-(void) Tel1
{
Direct dialing, and will remain in the call log when the dial is completed
Nsurl *url = [Nsurl urlwithstring:@ "tel://10010"];

[[UIApplication sharedapplication] openurl:url];
}

3.2. Go out and call and come back.

-(void) Tel2
{
However: the Telprompt protocol belongs to Apple's proprietary protocol, which cannot be listed once the protocol is used in the program
Systems developed for jailbroken machines can use this Protocol
Nsurl *url = [Nsurl urlwithstring:@ "telprompt://10010"];

[[UIApplication sharedapplication] openurl:url];
}

3.3 Call with UIWebView (will come back)
This is generally used to solve the problem of not jailbreak.


-(void) Tel3
{
//Tip: Do not add WebView to Self.view, if added will obscure the original view
//Lazy loading
if (_webview = = nil) {
_webview = [[UIWebView alloc] init];
}
NSLog (@ "%p", _webview);

//_webview = [[UIWebView alloc] initWithFrame:self.view.bounds];
//[Self.view Addsubview:_webview];

Nsurl *url = [Nsurl urlwithstring:@ "tel://10010"];
nsurlrequest *request = [Nsurlrequest requestwithurl:url];

[_webview loadrequest:request];
}

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.