We know we can use thisCodeSend text messages to the iPhone:
[[Uiapplication sharedapplication] Openurl: @ "SMS: 12345678"];
However, the text message content cannot be specified in this way. Then we can use the messageui framework.
FirstProgram. Import header file:# Import"Devicedetection. H"
Then, use the following statement in the code to call the SMS sending window and specify the number and text message content:
Mfmessagecomposeviewcontroller* Controller = [[[Mfmessagecomposeviewcontroller Alloc]Init]Autorelease];
Controller.Body=@ "ZC";
Controller.Recipients= [Nsarray Arraywithobjects:@ "106295598",Nil];
Controller.Messagecomposedelegate=Self;
[Self Presentmodalviewcontroller: ControllerAnimated:Yes];
The mfmessagecomposeviewcontrollerdelegate protocol is also implemented,
In the Protocol method messagecomposeviewcontroller: didfinishwithresult:
In the dissolution window:
Switch(Result ){
Case Messagecomposeresultcancelled:
Nslog(@ "Cancelled");
Break;
Case Messagecomposeresultfailed:
[Self Alert:@"An error occurred while sending the SMS!"];
Break;
Case Messagecomposeresultsent:
Break;
Default:
Break;
}
[Self Dismissmodalviewcontrolleranimated:Yes];