iOS phone, text message, email function

Source: Internet
Author: User

The following are the methods that are found on the Internet during the learning process,

To achieve the function of the call, the main two methods, the following I will say their advantages and disadvantages.
1.1. Texting (1)--url
Direct dialing, and will remain in the call log when the dial is completed
1. Method:
Nsurl *url = [Nsurl urlwithstring:@ "sms://10010"]; [[UIApplication sharedapplication] openurl:url];
2. Advantages:
– Simple
3. 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
1. Get back from the app
2. Can be many people
3. Can customize the message, the message supports the HTML format

And if in the Apple system, if each other's mobile phones are iOS devices, and opened the IMessage function, the message between each other is to take the network channel, but not 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    controller.recipients = @[@ "10010", @ "10086"];        2) SMS content    Controller.body = @ "For your old age, I wish you a happy old age!" ";        3) Set proxy    controller.messagecomposedelegate = self;    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 Agent method/** SMS Send results  messagecomposeresultcancelled,     cancel Messagecomposeresultsent,          send messagecomposeresultfailed         failure */-(void) Messagecomposeviewcontroller: (Mfmessagecomposeviewcontroller *) Controller didfinishwithresult: (messagecomposeresult) result{    NSLog (@ "%d", result);        In object-oriented programming 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 the message can be sent if (![    Mfmailcomposeviewcontroller Cansendmail]) {//Prompt the user to set the mailbox return; }//2.        Instantiate the mail controller and prepare to send mail mfmailcomposeviewcontroller *controller = [[Mfmailcomposeviewcontroller alloc] init];    1) The work report of the subject 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) Body [controller setmessagebody:@ "This is my <font color=\" blue\ "> Work report &L T;/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 What applications to use to open attachments//3> recipients to see the file name//You can add multiple attachments [controller ADDATTACHMENTD        Ata:imagedata mimetype:@ "Image/png" filename:@ "Avatar. png"];        7) Set agent [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,          save message Mfmailcomposeresultsent, 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, will stay in the call log when the dial is complete    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 private agreement, and once this protocol is used in the program, the program cannot be on the shelves    /system developed for jailbroken machines, you 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{    //Hint: Do not add WebView to Self.view if add will obscure the original view    //Lazy load    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];}

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.