IOS App Sending SMS

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.