Phone, SMS is the basic function of the phone, iOS provides the interface, let us call. This article simply describes how iOS calls and text messages are called in the program.
1. Call
[CPP]View PlainCopyprint?
- [[UIApplication sharedapplication] openurl:[nsurl urlwithstring:@"tel://10010"]];//call
Use OpenURL this API call end, return is the system to call the interface, how to return to their own application? There are two ways to share with you.
The first is to load the phone with UIWebView, which is legal and can be used on the App store.
The code is as follows:
[CPP]View PlainCopyprint?
- Uiwebview*callwebview =[[uiwebview alloc] init];
- Nsurl *telurl =[nsurl urlwithstring:@"tel:10010"];
- [Callwebview loadrequest:[nsurlrequest Requestwithurl:telurl];
- Remember to add to the view
- [Self.view Addsubview:callwebview];
The second is a private method, not on the App Store (you haven't tried it).
[CPP]View PlainCopyprint?
- [[UIApplication sharedapplication] openurl:[nsurl urlwithstring:@"telprompt://10010"];
The above code just puts the first method of Tel as telprompt.
2. Send SMS
There are two ways to send text messages in iOS, the simplest of which is to use OpenURL:
[CPP]View PlainCopyprint?
- [[UIApplication Sharedapplication]openurl:[nsurl urlwithstring:@"sms://10010"]];// texting
The above method can not specify the text message content, iOS4.0 New added Mfmessagecomposeviewcontroller and mfmessagecomposeviewcontrollerdelegate, provide the interface to send SMS, You can send text messages as you do without jumping out of the program. Description can be found in message uiframework Reference
Mfmessagecomposeviewcontroller provides the operation interface must be checked before using the Cansendtext method, if the return of no should not show the controller, but should be prompted to not support the sending of SMS.
Messagecomposedelegate: agent, processing send results
Recipients: Recipient < list, support group >
Body: SMS Content
To introduce messageui.framework in frameworks
#import <MessageUI/MessageUI.h>
Add Protocol:<mfmessagecomposeviewcontrollerdelegate>
[CPP]View PlainCopyprint?
- #import <MessageUI/MessageUI.h>
- @interface Demoviewcontroller:uiviewcontroller <MFMessageComposeViewControllerDelegate>
- @end
Call Mfmessagecomposeviewcontroller, and implement protocol mfmessagecomposeviewcontrollerdelegate.
[CPP]View PlainCopyprint?
- -(void) Showmessageview
- {
- if ([Mfmessagecomposeviewcontroller Cansendtext]) {
- Mfmessagecomposeviewcontroller * Controller = [[Mfmessagecomposeviewcontroller alloc]init]; //autorelease];
- controller.recipients = [Nsarray arraywithobject:@"10010"];
- Controller.body = @"Test texting";
- Controller.messagecomposedelegate = self;
- [Self Presentmodalviewcontroller:controller animated:yes];
- [[[Controller viewcontrollers] lastobject] navigationitem] settitle:@"Test SMS"]; //Modify SMS interface title
- }else{
- [Self alertwithtitle:@"message" msg:@ "device does not have SMS function"];
- }
- }
- Mfmessagecomposeviewcontrollerdelegate
- -(void) Messagecomposeviewcontroller: (Mfmessagecomposeviewcontroller *) controller didfinishwithresult: ( Messagecomposeresult) result{
- [Controller Dismissmodalviewcontrolleranimated:no]; //The key sentence cannot be Yes
- switch (result) {
- Case messagecomposeresultcancelled:
- [Self alertwithtitle:@"message" msg:@ "send Cancel"];
- Break ;
- Case messagecomposeresultfailed://Send failed
- [Self alertwithtitle:@"prompt message" msg:@"send Success"];
- Break ;
- Case Messagecomposeresultsent:
- [Self alertwithtitle:@"message" msg:@ "send Failed"];
- Break ;
- Default:
- Break ;
- }
- }
- -(void) Alertwithtitle: (NSString *) title msg: (NSString *) msg {
- Uialertview *alert = [[Uialertview alloc] Initwithtitle:title
- Message:msg
- Delegate:self
- Cancelbuttontitle:nil
- otherbuttontitles:@"OK", nil];
- [Alert show];
- }
Send an email for reference
/*** @author Zhang Xingye * http://blog.csdn.net/xyz_lmn* iOS starter Group: 83702688* Android Development Advanced Group: 241395671* my Sina Weibo:@ Zhang Xingye tbow*/
Reference:
http://developer.apple.com/library/ios/#documentation/messageui/reference/mfmessagecomposeviewcontroller_class /reference/reference.html
iOS basic texting and calling