iOS SMS Feature

Source: Internet
Author: User

Let's start by introducing one of the simplest methods:

Call Call function

[[Uiapplicationsharedapplication] Openurl:[nsurl urlwithstring:@ "tel://10086"];

Call to send SMS function

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


The above text messaging function is to call the system interface, the following is a click to implement a button to send text messages directly, equivalent to send the background, can be on the software store, not sure. Relative recommendations, try to use the first one.

First import mfmessagecomposeviewcontrollerdelegate This agent, implement the method inside

-(void) Messagecomposeviewcontroller: (mfmessagecomposeviewcontroller *) Controllerdidfinishwithresult: (messagecomposeresult) Result {

//notifies users about errors associated with the interface

Switch (Result) {

Case messagecomposeresultcancelled:

if (DEBUG) NSLog (@ "result:canceled");

break;

Case messagecomposeresultsent:

if (DEBUG) NSLog (@ "result:sent");

break;

Case messagecomposeresultfailed:

if (DEBUG) NSLog (@ "result:failed");

break;

default:

break;

}

[ self dismissmodalviewcontrolleranimated:YES];

}

Mass SMS:

-(ibaction) sendsms {

BOOL cansendsms = [mfmessagecomposeviewcontrollercansendtext];

NSLog (@ "can send SMS [%d]", cansendsms);

if (cansendsms) {

mfmessagecomposeviewcontroller *picker = [[mfmessagecomposeviewcontrolleralloc] Init];

Picker. messagecomposedelegate =self;

Picker. Navigationbar. Tintcolor = [uicolorblackcolor];

Picker. Body = @ "Test";

Picker. Recipients = [nsarrayarraywithobject:@ "10086"];

[ self presentmodalviewcontroller:p icker animated:YES];

[Picker release];

}

}

Send a text message to a person:

Get content from a Web page

-(void) Displaysmscomposersheet

{

mfmessagecomposeviewcontroller *picker = [[mfmessagecomposeviewcontrolleralloc] Init];

Picker. messagecomposedelegate =self;

UIWebView *web = nil;

nsmutablestring* Absurl = [[nsmutablestringalloc] initwithstring: Web. Request. URL. absolutestring];

[Absurl replaceoccurrencesofstring:@ "http://i.aizheke.com"withstring:@ "/http/ M.aizheke.com "options:nscaseinsensitivesearchrange:nsmakerange (0, [absurllength])];

Picker. body=[nsstringstringwithformat:@ " I see in the Love fold:%@ may be useful to you, Recommend to you! link:%@ ", [webstringbyevaluatingjavascriptfromstring:@" Document.title " ],absurl];

[Absurl release];

[ self presentmodalviewcontroller:p icker animated:YES];

[Picker release];

}

Event binding Send SMS

-(ibaction) Showsmspicker: (ID) Sender {

Class MessageClass = (nsclassfromstring(@ "Mfmessagecomposeviewcontroller"));

if (MessageClass! = Nil) {

if ([MessageClass cansendtext]) {

[ self displaysmscomposersheet];

}

Else {

// device does not have SMS function

}

}

Else {

//IOS version too low , iOS4.0 above to support sending SMS within the program

}

}


iOS SMS Feature

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.