Article reprint address: http://www.headsky.org/?p=63
IOS4.0 added Mfmessagecomposeviewcontroller and mfmessagecomposeviewcontrollerdelegate, providing an interface for sending text messages, You can send text messages as you do without jumping out of the program. Introduction can be found in the message UI
Framework Reference
Some notes:
Mfmessagecomposeviewcontroller
- Provides an operator interface
- The Cansendtext method must be checked before use, and if no is returned, the controller should not be shown, and the user should be prompted not to support sending SMS.
- Interface cannot be customized by itself
- The content (body) of the text message to be sent and the recipient (recipients) need to be initialized before displaying the controller, and the message content cannot be modified by the program. But users can still manually modify the text message content and select recipients
- When a user points a send or cancel, or fails to send, Mfmessagecomposeviewcontrollerdelegate's –messagecomposeviewcontroller:didfinishwithresult: Methods can be notified and handled accordingly.
If running on iOS3.0, you will be prompted Dyld:symbol not found: _objc_class_$_mfmessagecomposeviewcontroller. Solution:
- The introduction type of Messageui.framework should be selected weak (at Target, Get Info, General, Linked Libraries, Messageui.framework-&G T Modified in Type)
- Do not import messageui/mfmessagecomposeviewcontroller.h directly in. h file, change to import <MessageUI/MessageUI.h>
#pragmaMark-#pragmaMark Sms-(Ibaction) Showsmspicker: (ID) Sender {//The Mfmessagecomposeviewcontroller class is a available in IPhone OS 4.0 or later. //So, we must verify the existence of the above class and log a error message for Devices//running earlier versions of the IPhone OS. Set feedbackmsg If device doesn ' t support//Mfmessagecomposeviewcontroller API.Class MessageClass =(Nsclassfromstring (@ "Mfmessagecomposeviewcontroller")); if(MessageClass! =Nil) { //Check Whether the current device was configured for sending SMS messages if([MessageClass Cansendtext]) {[Self displaysmscomposersheet]; } Else{[Uialertview quickalertwithtitle:@"device does not have SMS function"Messagetitle:nil Dismisstitle:@"Close"]; } } Else{[Uialertview quickalertwithtitle:@"iOS version is too low for iOS4.0 to send SMS within the program"Messagetitle:nil Dismisstitle:@"Close"]; }}-(void) displaysmscomposersheet{Mfmessagecomposeviewcontroller*picker =[[Mfmessagecomposeviewcontroller alloc] init]; Picker.messagecomposedelegate=Self ; Nsmutablestring* Absurl =[[Nsmutablestring alloc] initWithString:web.request.URL.absoluteString]; [Absurl replaceoccurrencesofstring:@"http://i.aizheke.com"Withstring:@"http://m.aizheke.com"Options:nscaseinsensitivesearch Range:nsmakerange (0, [Absurl length])]; Picker.body=[nsstring stringWithFormat:@"I see in the Love Fold guest:%@ may be useful to you, recommend to you! link:%@", [Web stringbyevaluatingjavascriptfromstring:@"Document.title"], Absurl]; [Absurl release]; [Self presentmodalviewcontroller:picker animated:yes]; [Picker release];}- (void) Messagecomposeviewcontroller: (Mfmessagecomposeviewcontroller *Controller Didfinishwithresult: (messagecomposeresult) Result {Switch(Result) { Casemessagecomposeresultcancelled:log_expr (@ "result:sms sending canceled"); Break; Casemessagecomposeresultsent:log_expr (@ "result:sms sent"); Break; Casemessagecomposeresultfailed: [Uialertview quickalertwithtitle:@"SMS Send failed"Messagetitle:nil Dismisstitle:@"Close"]; Break; default: log_expr (@ "result:sms not sent"); Break; } [self dismissmodalviewcontrolleranimated:yes];}
SMS Mfmessagecomposeviewcontroller in iOS program