1, the procedure outgoing SMS
[[UIApplication Sharedapplication]openurl:[nsurl urlwithstring: @sms://10086]];
2, the program to send text messages, after the text message automatically return to the application
(1) First import frame Messageui.framework
(2) Introduction of header file #import <MessageUI/MessageUI.h>
(3) Implement Agent method <mfmessagecomposeviewcontrollerdelegate, uinavigationcontrollerdelegate >
3, directly on the code
-(void) showmessageview{ if ([Mfmessagecomposeviewcontroller Cansendtext]) { Mfmessagecomposeviewcontroller *controller = [[Mfmessagecomposeviewcontroller alloc] init]; controller.recipients = [Nsarray arraywithobject:@ "10086"]; Controller.body = @ "Test texting"; Controller.messagecomposedelegate = self; [Self Presentviewcontroller:controller animated:yes completion:nil]; [[[Controller viewcontrollers] lastobject] navigationitem] settitle:@ "Test SMS"]; } else{ [Self alertwithtitle:@ "message" msg:@ "device does not have SMS function"];} }
-(void) Messagecomposeviewcontroller: (Mfmessagecomposeviewcontroller *) controller didfinishwithresult: ( Messagecomposeresult) result{[controller Dismissviewcontrolleranimated:yes Completion:nil]; Switch (Result) {case messagecomposeresultcancelled: [Self alertwithtitle:@ "prompt message" msg:@ "send Cancel"]; Break Case messagecomposeresultfailed: [Self alertwithtitle:@ "message" msg:@ "Send Failed"]; Break Case messagecomposeresultsent: [Self alertwithtitle:@ "message" msg:@ "send Success"]; 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]; }
Texting within iOS program