Click the Send SMS button to jump to the SMS interface to send SMS

Source: Internet
Author: User

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

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.