SMS mfmessagecomposeviewcontroller in IOS Program

Source: Internet
Author: User

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:

  1. Select weak for the introduced type of messageui. Framework (modify it in target-> get info-> General-> linked libraries-> messageui. Framework-> type)
  2. 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];}
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.