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 you follow the agent and MFMessageComposeViewControllerDelegate
implement the proxy method.
#pragma mark-Proxy method
-(void) Messagecomposeviewcontroller: (Mfmessagecomposeviewcontroller *) controller Didfinishwithresult: (messagecomposeresult) result
{
[self dismissviewcontrolleranimated:yes completion: NIL];
Switch (Result) {case
messagecomposeresultsent:
//Information transmission successful break
;
Case messagecomposeresultfailed:
//Information transmission failed break
;
Case messagecomposeresultcancelled:
//Information cancelled by the user transmission 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:@ "prompt info"
message:@ "This device does not support SMS features"
Delegate:nil
cancelbuttontitle:@ "Determine"
otherbuttontitles:nil, nil];
[Alert show];
}
Finally, the method of sending a text message is called
Copy Code code as follows:
[Self Showmessageview:[nsarray arraywithobjects:@ "15888888888", @ "12399999999", Nil] title:@ "test" body:@ "This is a test message, Don't reply! "];
The above is a small series of iOS to introduce the system to send text messages to the two methods, I hope to help.