SMS in IOS Program

Source: Internet
Author: User
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:

    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/mfmessagecomposeviewcontroller. h In the. h file, and change it to import <messageui/messageui. h>

Code:

01 # Pragma mark-
02 # Pragma mark SMS
03  
04 -(Ibaction) showsmspicker :( ID) sender {
05 // The mfmessagecomposeviewcontrollerClass Is only availableIn IPhoneOS 4.0 Or Later.
06 // So, we must verify the existence of the aboveClass And Log an error messageFor Devices
07 // Running earlier versions of the iPhoneOS. Set feedbackmsgIf Device doesn' t support
08 // MfmessagecomposeviewcontrollerAPI.
09 Class Messageclass = (nsclassfromstring (@"Mfmessagecomposeviewcontroller"));
10  
11 If (Messageclass! =Nil){
12 // Check whether the current device is configuredFor SendingSMS Messages
13 If ([Messageclass cansendtext]) {
14 [Self Displaysmscomposersheet];
15 }
16 Else {
17 [Uialertview quickalertwithtitle :@"The device does not have the SMS function" Messagetitle: Nil Dismisstitle :@"Close"];
18 }
19 }
20 Else {
21 [Uialertview quickalertwithtitle :@"IOS version is too low. Only iOS or later supports sending SMS messages in the program" Messagetitle: Nil Dismisstitle :@"Close"];
22 }
23 }
24  
25 -(Void) displaysmscomposersheet
26 {
27 Mfmessagecomposeviewcontroller * picker = [[mfmessagecomposeviewcontroller alloc] init];
28 Picker. messagecomposedelegate =Self;
29  
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])];
32  
33 Picker. Body = [nsstring stringwithformat :@"% @ May be useful to you and I recommend it to you! Link: % @"
34 , [Web stringbyevaluatingjavascriptfromstring :@"Document. Title"]
35 , Absurl];
36 [Absurl release];
37 [Self Presentmodalviewcontroller: Picker Animated:Yes];
38 [Picker release];
39 }
40  
41 -(Void) messagecomposeviewcontroller :( mfmessagecomposeviewcontroller *) Controller
42 Didfinishwithresult :( messagecomposeresult) Result {
43  
44 Switch (result)
45 {
46 Case Messagecomposeresultcancelled:
47 Log_expr(@"Result: SMS sending canceled");
48 Break;
49 Case Messagecomposeresultsent:
50 Log_expr(@"Result: sms sent");
51 Break;
52 Case Messagecomposeresultfailed:
53 [Uialertview quickalertwithtitle :@"SMS sending failed" Messagetitle: Nil Dismisstitle :@"Close"];
54 Break;
55 Default:
56 Log_expr(@"Result: SMS not sent");
57 Break;
58 }
59 [Self Dismissmodalviewcontrolleranimated:Yes];
60 }
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.