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.
}
}