1. Import Messageui.framework
In 2.ViewController
#import <MessageUI/MessageUI.h>
Create a button trigger to send text messages
UIButton *btn =[uibutton Buttonwithtype:uibuttontypecustom];
Btn.frame = CGRectMake (150, 150, 50, 50);
[Self.view ADDSUBVIEW:BTN];
[Btn addtarget:self Action: @selector (BTN:) forcontrolevents:uicontroleventtouchupinside];
[Btn settitle:@ "invitation" forstate:uicontrolstatenormal];
Btn.backgroundcolor = [Uicolor Greencolor];
-(void) BTN: (UIButton *) Sender {
[Self Showmessageview:[nsarray arraywithobject:@ "17006698689"] title:@ "test" body:@ "Test 1"];
}
-(void) Messagecomposeviewcontroller: (Mfmessagecomposeviewcontroller *) controller didfinishwithresult: ( Messagecomposeresult) Result {
[Self Dismissviewcontrolleranimated:yes completion:^{
Switch (Result) {
Case Messagecomposeresultsent:
{
Message Delivery Success
}
Break
Case messagecomposeresultfailed:
{
Message Delivery failed
}
Break
Case messagecomposeresultcancelled:
{
Message canceled by user
{
}
}
Break
Default
Break
}
}];
}
Send SMS
-(void) Showmessageview: (Nsarray *) phones title: (NSString *) title body: (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];
}else {
NSLog (@ "The device does not support SMS");
}
}
IOS App Sending SMS