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
[[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:
Uiwebview*callwebview =[[uiwebview alloc] init]; Nsurl *telurl =[nsurl urlwithstring:@ "tel:10010"]; [Callwebview loadrequest:[nsurlrequest Requestwithurl:telurl]; Remember to add to view [Self.view Addsubview:callwebview];
The second is a private method, not on the App Store (you haven't tried it).
[[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:
[[UIApplication sharedapplication]openurl:[nsurl urlwithstring:@ "sms://10010"]];//texting
The above method can not specify the text message content,iOS4.0 New added Mfmessagecomposeviewcontroller and Mfmessagecomposeviewcont Rollerdelegate, provides an interface to send text messages, you can send a message as you do not have to jump out of the program to send text messages. Introduction can be found in message uiframework Reference
Mfmessagecomposeviewcontroller the Cansendtext method must be checked before the operating interface is used , and if no is returned, the Controller to display, but should prompt The user does not support sends the text message function.
Messagecomposedelegate: agent, processing send results
Recipients: Recipient < list, support group >
Body: SMS Content
To introduce messageui.framework in frameworks
#import <MessageUI/MessageUI.h>
Add Agreement:<MFMessageComposeViewControllerDelegate>
#import <MessageUI/MessageUI.h> @interface Demoviewcontroller:uiviewcontroller < Mfmessagecomposeviewcontrollerdelegate> @end
Call Mfmessagecomposeviewcontroller, and implement protocol mfmessagecomposeviewcontrollerdelegate.
-(void) showmessageview{if ([Mfmessagecomposeviewcontroller Cansendtext]) {Mfmessagecomposeviewcon Troller * 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 al ertwithtitle:@ "prompt message" msg:@ "device does not have SMS function"]; }}//mfmessagecomposeviewcontrollerdelegate-(void) Messagecomposeviewcontroller: (Mfmessagecomposeviewcontroller * Controller didfinishwithresult: (messagecomposeresult) result{[controller Dismissmodalviewcontrolleranimated:no] ;//Key sentence cannot be ' yes ' switch (result) {case messagecomposeresultcancelled: ' Self alert ' withtitle:@"Prompt 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] Initwit Htitle:title message:msg delegate:self cancelbuttontitle:nil otherbuttontitles:@ " [Nil]; [Alert show]; }