Texting within iOS program

Source: Internet
Author: User

1, the procedure outgoing SMS

[[UIApplication Sharedapplication]openurl:[nsurl urlwithstring: @sms://10086]];

  

2, the program to send text messages, after the text message automatically return to the application

(1) First import frame Messageui.framework

(2) Introduction of header file #import <MessageUI/MessageUI.h>

(3) Implement Agent method <mfmessagecomposeviewcontrollerdelegate, uinavigationcontrollerdelegate >

3, directly on the code

-(void) showmessageview{        if ([Mfmessagecomposeviewcontroller Cansendtext]) {                Mfmessagecomposeviewcontroller *controller = [[Mfmessagecomposeviewcontroller alloc] init];                controller.recipients = [Nsarray arraywithobject:@ "10086"];                Controller.body = @ "Test texting";                Controller.messagecomposedelegate = self;                 [Self Presentviewcontroller:controller animated:yes completion:nil];                [[[Controller viewcontrollers] lastobject] navigationitem] settitle:@ "Test SMS"];    } else{                [Self alertwithtitle:@ "message" msg:@ "device does not have SMS function"];}    }

  

-(void) Messagecomposeviewcontroller: (Mfmessagecomposeviewcontroller *) controller didfinishwithresult: (        Messagecomposeresult) result{[controller Dismissviewcontrolleranimated:yes Completion:nil];            Switch (Result) {case messagecomposeresultcancelled: [Self alertwithtitle:@ "prompt message" msg:@ "send Cancel"];                    Break            Case messagecomposeresultfailed: [Self alertwithtitle:@ "message" msg:@ "Send Failed"];                    Break            Case messagecomposeresultsent: [Self alertwithtitle:@ "message" msg:@ "send Success"];                    Break    Default:break;  }}-(void) Alertwithtitle: (NSString *) title msg: (NSString *) msg {Uialertview *alert = [[Uialertview alloc]                                                   Initwithtitle:title message:msg                               Delegate:self Cancelbuttontitle:nil           otherbuttontitles:@ "OK", nil];      [Alert show]; }

  

Texting within iOS program

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.