Home > DeveloperSection > Forums > How to send messages in iPhone
Lillian Martin

Total Post:27

Points:189
Posted on    February-19-2015 12:54 AM

 iPhone iPhone  Ios 
Ratings:


 1 Reply(s)
 484  View(s)
Rate this:
How to send messages in iPhone ?


Allen Scott

Total Post:37

Points:261
Supported
Posted on    February-19-2015 1:26 AM

Few steps will led u to understand the simple implementation involved in it:

 

Step.1-Include  MessageUI.framework in your project.


Step-2 Import  MessageUI/MessageUI.h in your header file like that in my case.

#import <MessageUI/MessageUI.h>

#import <UIKit/UIKit.h>

#import <QuartzCore/QuartzCore.h>

 

@interface SendSMS : UITableViewController<MFMessageComposeViewControllerDelegate>

@property (retain, nonatomic) NSString *SMSSubject;

@end

 

Setp-3 Suppose you want to send SMS on button  touch(click) then write the following code in your implementation (SendSMS.m) file.

 

  MFMessageComposeViewController *controller =[[MFMessageComposeViewController alloc] init];

     controller.messageComposeDelegate = self;

 

// CHECK DEVICE CAN SEND TEXT MESSAGE. 

    if([MFMessageComposeViewController canSendText]){

// message subject.

       controller.subject=@this is message subject. ;

//  message body

    controller.body=[NSString stringWithFormat:@ This is the testing message. ];


// contact number you want to send .

        controller.recipients = [NSArray arrayWithObjects:@ 123456,nil]; 

        

// check the condition in case of model view controller is not dismissed.

                if (![[self presentedViewController] isBeingPresented]) {

                    [self dismissViewControllerAnimated:YES completion:nil];

                 

                }

// show message view  UI.

[self presentViewController: controller animated:YES completion:nil];

            }

 

// delegate method of  MFMessageComposeViewController .


- (void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result

{

      [controller dismissViewControllerAnimated:YES completion:nil];

}


Modified On Feb-19-2015 01:37:30 AM

Don't want to miss updates? Please click the below button!

Follow MindStick