An example of IOS calling system texting

Source: Internet
Author: User

One, the program outward use system text message

This method is actually very simple, direct call OpenURL can:


Nsurl *url = [Nsurl urlwithstring:@ "sms://15888888888"];
[[UIApplication Sharedapplication]openurl:url];

Second, the program calls the system to send text messages

One advantage of this approach is that users can return to the app after texting.
First you import the messageui.framework and introduce the header file:

#import <MessageUI/MessageUI.h>

Then follow the agent Mfmessagecomposeviewcontrollerdelegate and implement the proxy method.

#pragma mark-Agent method
-(void) Messagecomposeviewcontroller: (Mfmessagecomposeviewcontroller *) controller didfinishwithresult: ( Messagecomposeresult) Result
{
[Self dismissviewcontrolleranimated:yes completion:nil];
Switch (Result) {
Case Messagecomposeresultsent:
Information delivered successfully

Break
Case messagecomposeresultfailed:
Information transfer failed

Break
Case messagecomposeresultcancelled:
Message canceled by user

Break
Default
Break
}
}

Send SMS method to achieve

#pragma mark-Send SMS Method
-(void) Showmessageview: (Nsarray *) phones title: (NSString *) title: (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];//Modify SMS interface title
}
Else
{
Uialertview *alert = [[Uialertview alloc] initwithtitle:@ ' hint info '
message:@ "This device does not support SMS Features"
Delegate:nil
cancelbuttontitle:@ "OK"
Otherbuttontitles:nil, nil];
[Alert show];
}
}

Finally, the method of sending a text message is called


[Self Showmessageview:[nsarray arraywithobjects:@ "15888888888", @ "12399999999", Nil] title:@ "test" body:@ "This is a test message, Don't reply! "];

Related Article

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.