Phones and text messages are the basic functions of mobile phones. IOS provides interfaces for us to call. This articleArticleA Brief Introduction of IOS phone calls and text messagesProgram.
1. Call
[[Uiapplication sharedapplication] Openurl: [nsurl urlwithstring: @ "Tel: // 10010"]; // call
After calling the Openurl API, the system's call interface is returned. How can I return my own applications? There are two ways to share with you.
The first is to use uiwebview to load the phone. This is legal and can be used to store the app.
CodeAs follows:
Uiwebview * callwebview = [[uiwebview alloc] init]; nsurl * telurl = [nsurl urlwithstring: @ "Tel: 10010"]; [callwebview loadrequest: [nsurlrequest requestwithurl: telurl]; // remember to add it to the view [self. view addsubview: callwebview];
The second method is a private method, which cannot be used for App Store (you have never tried it ).
[[Uiapplication sharedapplication] Openurl: [nsurl urlwithstring: @ "telprompt: // 10010"];
The above Code only sets Tel In the first method as telprompt.
2. send text messages
In iOS, you can use either of the following methods to send text messages:
[[Uiapplication sharedapplication] Openurl: [nsurl urlwithstring: @ "SMS: // 10010"]; // send a text message
the text message content cannot be specified in the preceding method. ios4.0 is added with mfmessagecomposeviewcont roller and mfmessagecomposeviewcont rollerdelegate, available the interface for sending text messages. You do not need to jump out of the program to send text messages like sending emails. for more information, see message uiframework reference
Mfmessagecomposeviewcontroller Provides an operation interface Use You must check the cansendtext method before. If no is returned, this Controller Instead Prompt You cannot send text messages.
Messagecomposedelegate: proxy for sending results
Recipients: Recipient <list, Supporting Group Sending>
Body: Text message content
Introduction In FrameworksMessageui. Framework
# Import<Messageui/messageui. h>
Add protocol:<MfmessagecomposeviewcontRollerdelegate>
# Import <messageui/messageui. h> @ interface demoviewcontroller: uiviewcontroller <mfmessagecomposeviewcontrollerdelegate> @ end
call mfmessagecomposeviewcontroller , the mfmessagecomposeviewcontrollerdelegate protocol is also implemented.
-(Void) showmessageview {If ([mfmessagecomposeviewcontroller cansendtext]) {mfmessagecomposeviewcontroller * controller = [[mfmessagecomposeviewcontroller alloc] init]; // autorelease]; controller. recipients = [nsarray arraywithobject: @ "10010"]; controller. body = @ "test text message"; controller. messagecomposedelegate = self; [self presentmodalviewcontroller: controller animated: Yes]; [[[controller viewcontrollers] lastobject] navigationitem] settitle: @ "test SMS"]; // modify the text message interface title} else {[self alertwithtitle: @ "prompt message" MSG: @ "the device has no SMS function"] ;}}// mfmessagecomposeviewcontrollerdelegate-(void) messagecomposeviewcontroller :( mfmessagecomposeviewcontroller *) controller didfinishwithresult :( messagecomposeresult) Result {[controller failed: No]; // The key sentence cannot be yes switch (result) {case when: [self alertwithtitle: @ "prompt message" MSG: @ "cancel sending"]; break; Case messagecomposeresultfailed: // send failed [self alertwithtitle: @ "prompt message" MSG: @ "sent successfully"]; break; Case messagecomposeresultsent: [self alertwithtitle: @ "prompt message" MSG: @ "failed to send"]; break; default: break ;}} -(void) alertwithtitle :( nsstring *) Title MSG :( nsstring *) MSG {uialertview * Alert = [[uialertview alloc] initwithtitle: Title message: MSG delegate: Self cancelbuttontitle: Nil failed: @ "OK", nil]; [alert show];}
For more information about sending emails, see
/**
* @ Author Zhang xingye* Http://blog.csdn.net/xyz_lmn* IOS entry group:83702688
* Android development advanced group:241395671
* My Sina Weibo:@ Zhang xingye tbow*/
Refer:
Http://developer.apple.com/library/ios/#documentation/MessageUI/Reference/MFMessageComposeViewController_class/Reference/Reference.html