Article reprint address: http://www.headsky.org /? P = 63
Ios4.0 added mfmessagecomposeviewcontRoroller and mfmessagecomposeviewcontRollerdelegate provides an interface for sending text messages. You do not need to jump out of a program to send text messages as you do when sending an email. For more information, see message UI.
Framework reference
Notes:
Mfmessagecomposeviewcont Roroller
- Provides an operation interface
- You must check the cansendtext method before using it. If no is returned, the Controller should not be displayed, but the system should prompt that the user does not support sending text messages.
- The interface cannot be customized by yourself.
- The content (body) and the recipient (recipients) of the text message to be sent must be initialized before the controller is displayed. After the display, the text message content cannot be modified through a program. however, you can manually modify the text message content and select recipients.
- When the user clicks send or cancel, or fails to send, mfmessagecomposeviewcontRollerdelegate-messagecomposeviewcontroRoller: didfinishwithresult: all methods can be notified and corresponding processing is performed here.
If running on ios3.0, the system prompts dyld: Symbol not found: _ objc_class _ $ _ mfmessagecomposeviewcont.Roller. solution:
- Select weak for the introduced type of messageui. Framework (modify it in target-> get info-> General-> linked libraries-> messageui. Framework-> type)
- Do not directly import messageui/mfmessagecomposeviewcont in the. h fileRoller. H, changed to import<Messageui/messageui. h>
# Pragma mark-# pragma mark SMS-(ibaction) showsmspicker :( ID) sender {// The mfmessagecomposeviewcontroller class is only available in iPhone OS 4.0 or later. // so, we must verify the existence of the above class and log an error message for devices // running earlier versions of the iPhone OS. set feedbackmsg if device doesn' t support // mfmessagecomposeviewcontroller API. class messageclass = (NSC Lassfromstring (@ "mfmessagecomposeviewcontroller"); If (messageclass! = Nil) {// check whether the current device is configured for sending SMS messages if ([messageclass cansendtext]) {[self displaysmscomposersheet];} else {[uialertview quickalertwithtitle: @ "the device does not have the SMS function" messagetitle: Nil dismisstitle: @ "close"] ;}} else {[uialertview quickalertwithtitle: @ "iOS version is too low, message messagetitle: Nil dismisstitle: @ "close"] ;}}- (void) displaysmscomposersheet {mfmessagecomp is supported only when ios4.0 or higher. Oseviewcontroller * 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 have seen on the love Guest: % @ may be useful to you. We recommend it 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) {case when: log_expr (@ "Result: SMS sending canceled"); break; Case messagecomposeresultsent: log_expr (@ "result: SMS sent "); break; Case messagecomposeresultfailed: [uialertview quickalertwithtitle: @" SMS failed to send "messagetitle: Nil dismisstitle: @" disabled "]; break; default: log_expr (@ "result: SMS not sent"); break;} [self dismissmodalviewcontrolleranimated: Yes];}