ArticleDirectory
- Mfmessagecomposeviewcontroller
Ios4.0 is added with mfmessagecomposeviewcontroller and mfmessagecomposeviewcontrollerdelegate. It provides an interface for sending text messages and does not need to jump out like sending an email.ProgramFor more information, see message UI.
Framework reference
Notes:
Mfmessagecomposeviewcontroller
- 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, the-messagecomposeviewcontrollerdelegate-messagecomposeviewcontroller: didfinishwithresult: method can be notified, and corresponding processing is performed here
If running on ios3.0, the system prompts dyld: Symbol not found: _ objc_class _ $ _ mfmessagecomposeviewcontroller. 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/mfmessagecomposeviewcontroller. h In the. h file, and change it to import <messageui/messageui. h>
Code:
04 |
-(Ibaction) showsmspicker :( ID) sender { |
05 |
// The mfmessagecomposeviewcontroller Class Is only available In IPhone OS 4 . 0 Or Later. |
06 |
// So, we must verify the existence of the above Class And Log an error message For Devices |
07 |
// Running earlier versions of the iPhone OS . Set feedbackmsg If Device doesn' t support |
08 |
// Mfmessagecomposeviewcontroller API . |
09 |
Class Messageclass = (nsclassfromstring (@ "Mfmessagecomposeviewcontroller" )); |
11 |
If (Messageclass! = Nil ){ |
12 |
// Check whether the current device is configured For Sending SMS Messages |
13 |
If ([Messageclass cansendtext]) { |
14 |
[ Self Displaysmscomposersheet]; |
17 |
[Uialertview quickalertwithtitle :@ "The device does not have the SMS function" Messagetitle : Nil Dismisstitle :@ "Close" ]; |
21 |
[Uialertview quickalertwithtitle :@ "IOS version is too low. Only iOS or later supports sending SMS messages in the program" Messagetitle : Nil Dismisstitle :@ "Close" ]; |
25 |
-(Void) displaysmscomposersheet |
27 |
Mfmessagecomposeviewcontroller * picker = [[mfmessagecomposeviewcontroller alloc] init]; |
28 |
Picker. messagecomposedelegate = Self ; |
30 |
Nsmutablestring * absurl = [[nsmutablestring alloc] initwithstring : Web . Request. URL . Absolutestring]; |
31 |
[Absurl replaceoccurrencesofstring :@ Http:// I .aizheke.com" Withstring :@ Http://m.aizheke.com" Options: nscaseinsensitivesearch range: nsmakerange ( 0 , [Absurl length])]; |
33 |
Picker. Body = [nsstring stringwithformat :@ "% @ May be useful to you and I recommend it to you! Link: % @" |
34 |
, [Web stringbyevaluatingjavascriptfromstring :@ "Document. Title" ] |
37 |
[ Self Presentmodalviewcontroller : Picker Animated: Yes ]; |
41 |
-(Void) messagecomposeviewcontroller :( mfmessagecomposeviewcontroller *) Controller |
42 |
Didfinishwithresult :( messagecomposeresult) Result { |
46 |
Case Messagecomposeresultcancelled: |
47 |
Log_expr (@ "Result: SMS sending canceled" ); |
49 |
Case Messagecomposeresultsent: |
50 |
Log_expr (@ "Result: sms sent" ); |
52 |
Case Messagecomposeresultfailed: |
53 |
[Uialertview quickalertwithtitle :@ "SMS sending failed" Messagetitle : Nil Dismisstitle :@ "Close" ]; |
56 |
Log_expr (@ "Result: SMS not sent" ); |
59 |
[ Self Dismissmodalviewcontrolleranimated: Yes ]; |