In app development, it may involve the functions of making calls, texting, and sending emails. For example, usually a product "about" page, there will be a developer's contact, ideally, when the user clicks on the phone number, can automatically help users dial out, it involves the function of the phone.
In iOS development, there are three ways to call:
(1) Jump directly to the dial-up interface, the code is as follows
Nsurl *url = [Nsurl urlwithstring:@ "tel://10010"]; [[UIApplication sharedapplication] openurl:url];
Disadvantage: After the call is finished, will not automatically return to the original application, directly stay on the call log page.
(2) Before dialing the box to ask, after the call can automatically return to the original application. The code is as follows:
Nsurl *url = [Nsurl urlwithstring:@ "telprompt://10010"]; [[UIApplication sharedapplication] openurl:url];
Cons: Private API, so may not pass Apple official audit. If you are an enterprise application (no online AppStore required), you can use this method.
(3) Create a uiwebview to load the URL, after the dial can automatically return to the original application. The code is as follows:
UIWebView *webview = [[UIWebView alloc]init]; Nsurl *url = [Nsurl urlwithstring:@ "tel://10010"]; [WebView loadrequest:[nsurlrequest Requestwithurl:url];
It is recommended to use the third method.
There are two ways to send text messages.
(1) Jump directly to the texting interface. Code:
Nsurl *url = [Nsurl urlwithstring:@ "sms://10010"]; [[UIApplication sharedapplication] openurl:url];
Disadvantage: Cannot define the content that sends the text message, and after sending the text message cannot automatically return to the original application.
(2) Use MESSAGEUI framework to send SMS, need to include header file #import <messageui/messageui.h>, the code is as follows:
Mfmessagecomposeviewcontroller *VC = [[mfmessagecomposeviewcontroller alloc]init];//set SMS content vc.body = @ "Eat no";// Set recipient list vc.recipients = @[@ "10010", @ "10086"];//set proxy vc.messagecomposedelegate = self;//display Controller [self PRESENTVIEWCONTROLLER:VC Animated:yes Completion:nil];
Also implement the proxy function:
/** * Clicking the Cancel button will automatically call the * */-(void) Messagecomposeviewcontroller: (Mfmessagecomposeviewcontroller *) controller Didfinishwithresult: (messagecomposeresult) result{ [controller Dismissviewcontrolleranimated:yes completion: NIL];}
It is recommended to use the second method.
There are two ways to send mail.
(1) with your own mail client, the code is as follows:
Nsurl *url = [Nsurl urlwithstring:@ "mailto://[email protected]"; [[UIApplication sharedapplication] openurl:url];
Disadvantage: Do not automatically return to the original application after sending the message
(2) Similar to the second method of texting, using Messageui, the code is as follows:
if (![ Mfmailcomposeviewcontroller Cansendmail]) return; Mfmailcomposeviewcontroller *VC = [[Mfmailcomposeviewcontroller alloc] init];//set message subject [VC setsubject:@ "test Meeting"];// Set message content [VC setmessagebody:@ "Meeting" ishtml:no];//set up recipient list [VC settorecipients:@[@ "[email protected]"]];//set CC list [VC setccrecipients:@[@ "[email protected]"]];//set proxy vc.mailcomposedelegate = self;//display Controller [self PRESENTVIEWCONTROLLER:VC Animated:yes Completion:nil];
To implement the Proxy method:
-(void) Mailcomposecontroller: (Mfmailcomposeviewcontroller *) controller didfinishwithresult: (mfmailcomposeresult) Result Error: (Nserror *) error{ [controller Dismissviewcontrolleranimated:yes Completion:nil];}
It is recommended to use the second method.
The implementation of phone texting and other functions in iOS development