SMS Mfmessagecomposeviewcontroller in iOS program

Source: Internet
Author: User

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:

    1. The introduction type of Messageui.framework should be selected weak (at Target, Get Info, General, Linked Libraries, Messageui.framework-&G T Modified in Type)
    2. 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

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.