SMS Functionality in iOS Development

Xcode provide MessageUI framework to send SMS from your ios application. This provide facility to send any text message from your application directly. Below steps will help to integrate SMS facility provided by Xcode,

1.    Import the MessageUI Framework into your project
#import <MessageUI/MessageUI.h>

2.    Write below method for any action control. We take button as example here,
(IBAction) sendInAppSMS:(id) sender
{
MFMessageComposeViewController *controller = [[[MFMessageComposeViewController alloc] init] autorelease];
if([MFMessageComposeViewController canSendText])
{
controller.body = @”Hello from Mugunth”;
controller.recipients = [NSArray arrayWithObjects:@”12345678″, @”87654321″, nil];
controller.messageComposeDelegate = self;
[self presentModalViewController:controller animated:YES];
}
}

3.    Do not forget to check that does your device support send SMS facility using canSendText method. If application doesn’t check this condition then it may cause crash for those device which are not support such a facility. Application can check this using below statement,
[MFMessageComposeViewController canSendText].

4.    Implement below Delegate methods in your controller. Add MFMessageComposeViewControllerDelegate and UINavigationControllerDelegate in .h file,
yourController.delegate = self;

(void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result
{
switch (result) {
case MessageComposeResultCancelled:
NSLog(@”Cancelled”);
break;
case MessageComposeResultFailed:
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@”MyApp” message:@”Unknown Error” delegate:self cancelButtonTitle:@”OK” otherButtonTitles: nil];
[alert show];
[alert release];
break;
case MessageComposeResultSent:

break;
default:
break;
}

[self dismissModalViewControllerAnimated:YES];
}

(Visited 5 times, 1 visits today)


Related Posts:

387
Author - admin_specindia

POPULAR BLOGS

Archives

  • 2017
  • 2016
  • 2015
  • 2014
  • 2013
  • 2012
  • 2011
  • 2010
  • 2009
  • 2008
  • Related Blogs

    Current Openings
    Scroll Up