One, the program outward use system text message
This method is actually very simple, direct call OpenURL can:
Nsurl *url = [Nsurl urlwithstring:@ "sms://15888888888"];
[[UIApplication Sharedapplication]openurl:url];
Second, the program calls the system to send text messages
One advantage of this approach is that users can return to the app after texting.
First you import the messageui.framework and introduce the header file:
#import <MessageUI/MessageUI.h>
Then follow the agent Mfmessagecomposeviewcontrollerdelegate and implement the proxy method.
#pragma mark-Agent method
-(void) Messagecomposeviewcontroller: (Mfmessagecomposeviewcontroller *) controller didfinishwithresult: ( Messagecomposeresult) Result
{
[Self dismissviewcontrolleranimated:yes completion:nil];
Switch (Result) {
Case Messagecomposeresultsent:
Information delivered successfully
Break
Case messagecomposeresultfailed:
Information transfer failed
Break
Case messagecomposeresultcancelled:
Message canceled by user
Break
Default
Break
}
}
Send SMS method to achieve
#pragma mark-Send SMS Method
-(void) Showmessageview: (Nsarray *) phones title: (NSString *) title: (NSString *) body
{
if ([Mfmessagecomposeviewcontroller Cansendtext])
{
Mfmessagecomposeviewcontroller * Controller = [[Mfmessagecomposeviewcontroller alloc] init];
controller.recipients = phones;
Controller.navigationBar.tintColor = [Uicolor Redcolor];
Controller.body = body;
Controller.messagecomposedelegate = self;
[Self Presentviewcontroller:controller animated:yes completion:nil];
[[[[[[[Controller viewcontrollers] lastobject] navigationitem] settitle:title];//Modify SMS interface title
}
Else
{
Uialertview *alert = [[Uialertview alloc] initwithtitle:@ ' hint info '
message:@ "This device does not support SMS Features"
Delegate:nil
cancelbuttontitle:@ "OK"
Otherbuttontitles:nil, nil];
[Alert show];
}
}
Finally, the method of sending a text message is called
[Self Showmessageview:[nsarray arraywithobjects:@ "15888888888", @ "12399999999", Nil] title:@ "test" body:@ "This is a test message, Don't reply! "];