IOS call system text message and call Functions

Source: Internet
Author: User

First, we will introduce the simplest method:

Call the call Function

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

Call the SMS function

[[Uiapplication sharedapplication] Openurl: [nsurl urlwithstring: @ "SMS: // 10000"];

 


The above text message function calls the system interface. The following is a method to send text messages directly by clicking the button, which is equivalent to sending messages in the background. It is still uncertain whether the messages can be sent to the software store. We recommend that you use the first method as much as possible.


First, import the mfmessagecomposeviewcontrollerdelegate proxy to implement the method in it.

-(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];

}

Group 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: picker animated: Yes];

[Picker release];

}

}

Send a text message to a person:
Obtain content from the webpage

-(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 have seen on love Guest: % @ may be useful to you. We recommend it to you! Link: % @ ", [webstringbyevaluatingjavascriptfromstring: @" document. Title "], absurl];

[Absurl release];

[Self presentmodalviewcontroller: picker animated: Yes];

[Picker release];

}

Send SMS by event binding

-(Ibaction) showsmspicker :( ID) sender {

Class messageclass = (nsclassfromstring (@ "mfmessagecomposeviewcontroller "));

If (messageclass! = Nil ){

If ([messageclass cansendtext]) {

[Self displaysmscomposersheet];

}

Else {

// The device does not have the SMS function

}

}

Else {

// IOS version is too low. messages can be sent in the program only when ios4.0 or later.

}

}

 

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.