Create a new Singleview code as follows:
#import "ViewController.h" @interface ViewController () @end @implementation viewcontroller- (void) Viewdidload { [super viewdidload]; nslog (@ "%@", Nshomedirectory ()); uibutton *button = [uibutton Buttonwithtype:uibuttontypecustom]; button.frame = cgrectmake (100, 100,  40, 30); [button settitle:@ "Send" forState:UIControlStateNormal]; [button settitlecolor:[uicolor blackcolor] forstate: uicontrolstatenormal]; button.backgroundcolor=[uicolor redcolor]; [self.view addsubview:button]; [button addtarget:self action : @selector (ButtonClick) forcontrolevents:uicontroleventtouchupinside];} - (void) buttonclick { //first determine whether the current device can beTo send SMS if ([Mfmessagecomposeviewcontroller cansendtext]) { mfmessagecomposeviewcontroller *mc=[[ mfmessagecomposeviewcontroller alloc] init]; //setting up a delegate mc.messagecomposedelegate=self; //SMS Content mc.body=[[NSString alloc] initwithutf8string: "Hello" ]; //Set SMS Recipient mc.recipients=[NSArray arraywithobject:@ "10010"]; [self presentviewcontroller:mc animated:yes completion:nil]; }else{ [[[uialertview alloc] initwithtitle:nil message:@ "Sorry, no this feature" delegate:self cancelbuttontitle:@ "?" otherButtonTitles:nil, nil] show]; }} //text message sent processing result-(void) Messagecomposeviewcontroller: ( mfmessagecomposeviewcontroller *) Controller didfinishwithresult: (Messagecomposeresult) result{ switch (Result) { case MessageComposeResultSent: nslog (@ "text message sent successfully"); break; case Messagecomposeresultcancelled: nslog (@ " Text message cancelled "); [ self dismissviewcontrolleranimated:yes completion:nil]; break; case Messagecomposeresultfailed: nslog (@ " Text message failed "); break; default: nslog (@ "Error happens"); break; } } @end
Click the Send SMS button to jump to the SMS interface to send SMS