Network Call Phone, Web, SMS, Email

Source: Internet
Author: User
Tags call back


1. Preparation: Import information UI Library #import <MessageUI/MessageUI.h>
2. Call Phone
   Way One: stitching the string note the beginning is Tel: this way can not call back to the original application, will stay in the address book, and direct calls do not have any popup window prompt
NSString *str = [NSString stringwithformat:@ "tel:%@", Self.phoneTextField.text];
First get the applied singleton object and then call OpenURL: This method parameter is the URL object
[[UIApplication sharedapplication] Openurl:[nsurl Urlwithstring:str]];
   mode Two: This way has popup window prompt, and can return to the original application recommended this
NSString *STR1 = [[NSString alloc] initwithformat:@ "tel:%@", Self.phoneTextField.text];
Create a UIWebView object
UIWebView *callwebview = [[UIWebView alloc] init];
Load a Request object this Request object creates a URL object from a URL object and obtains it through the STR1 string.
[Callwebview loadrequest:[nsurlrequest Requestwithurl:[nsurl URLWITHSTRING:STR1]];
Add to Self.view
[Self.view Addsubview:callwebview];
   mode three: This way can also have pop-up window tips and can also go back to the original application also recommended this
NSString *STR2 = [NSString stringwithformat:@ "telprompt:%@", Self.phoneTextField.text];
[[UIApplication sharedapplication] Openurl:[nsurl URLWITHSTRING:STR2]];
3. Web Open URL Note: Open the URL note is HTTP//or https://
NSString *str = [NSString stringwithformat:@ "https://%@", Self.webTextField.text];
[[UIApplication sharedapplication] Openurl:[nsurl Urlwithstring:str]];

4. SMS
   Way One: This way can not go back to the application, but pay attention not to write Chinese and other special characters otherwise unable to jump to the texting interface
   Pros: Simple disadvantage: Cannot specify the sending content, can only specify the sender, and can not go back to the application
NSString *str = [NSString stringwithformat:@ "sms://%@", Self.smsTextField.text];
Nsurl *url = [Nsurl urlwithstring:str];
[[UIApplication sharedapplication] openurl:url];
   Way Two: recommend this
   Pros: 1. From the application and can return to the application
2. Can send multiple people
3. You can customize the message with code
4. If the mobile phone has the imessage function, will take the network channel, does not walk the carrier channel

Determine if the user device can send text messages
if (![ Mfmessagecomposeviewcontroller Cansendtext]) {
NSLog (@ "Cannot send content");

return;
}

1. Create a text message controller object
Mfmessagecomposeviewcontroller *controller = [[Mfmessagecomposeviewcontroller alloc] init];

2. Set SMS Content
(1) Recipient
controller.recipients = @[@ "10086", @ "10010"];
(2) SMS content
Controller.body = @ "Hello, you Two";
(3) Set up SMS agent (to abide by Agent protocol Mfmessagecomposeviewcontrollerdelegate)
Controller.messagecomposedelegate = self;

3. Display SMS Controller

[Self Presentviewcontroller:controller animated:yes completion:^{
NSLog (@ "Show SMS Controller Completion code block");
}];

#pragma mark-SMS Controller proxy method
-(void) Messagecomposeviewcontroller: (Mfmessagecomposeviewcontroller *) controller didfinishwithresult: ( Messagecomposeresult) Result {

/*
messagecomposeresultcancelled, Cancel
Messagecomposeresultsent, send
messagecomposeresultfailed failure

Result Enumeration
*/
NSLog (@ "%d", result);

Note: Don't forget to go back to the app
[Controller Dismissviewcontrolleranimated:yes completion:^{
NSLog (@ "SMS controller disappears after completion of code block");
}];

}

5. Email
   Way One:
NSString *str = [NSString stringwithformat:@ "mailto://%@", Self.emailTextField.text];
[[UIApplication sharedapplication] Openurl:[nsurl Urlwithstring:str]];
   Way Two:
Determine if a message can be sent
if (![ Mfmailcomposeviewcontroller Cansendmail]) {
NSLog (@ "Cannot send mail");
Return
}
Create a mail Controller object
Mfmailcomposeviewcontroller *VC = [[Mfmailcomposeviewcontroller alloc] init];
Set Message subject
[VC setsubject:@ "1602 the first day of two weeks the second time sent"];
Set message send content the second parameter supports HTML formatting
[VC setmessagebody:@] Today mainly spoke of CoreData and basic telephone, mail, the web has been SMS "Ishtml:yes";
Set up a recipient list
[VC settorecipients:@[@ "[email protected]"];
Set up a CC person list
[VC setccrecipients:@[@ "[email protected]", @ "[email protected]"];
Set up the mail agent (to follow the mail agent mfmailcomposeviewcontrollerdelegate)
Vc.mailcomposedelegate = self;
Show Mail Controller
[Self PRESENTVIEWCONTROLLER:VC animated:yes completion:^{
NSLog (@ "EXECUTE code block after jump completion");
}];

#pragma mark-mail agent method
-(void) Mailcomposecontroller: (Mfmailcomposeviewcontroller *) controller didfinishwithresult: (mfmailcomposeresult) Result Error: (Nserror *) Error {

/*
Result enumeration type
mfmailcomposeresultcancelled, Cancel
Mfmailcomposeresultsaved, save
Mfmailcomposeresultsent, send
mfmailcomposeresultfailed failure
*/
NSLog (@ "%d", result);

[Controller Dismissviewcontrolleranimated:yes completion:^{
NSLog (@ "code block after the mailbox controller disappears");
}];

}

Network Call Phone, Web, SMS, Email

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.