Search This Blog

Wednesday, 2 November 2011

SMS Sending Integration



In this post i am going to guide for integration of SMS in your applicaiton.
so here we go!

//Import in your .h file

#import <MessageUI/MessageUI.h>

//Add framework
MessageUI.framework

//copy and paste these two functions in your .m file

- (void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result
{
switch (result) {
case MessageComposeResultCancelled:
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];
}
-(void)SMSComposer
{
MFMessageComposeViewController *controller = [[[MFMessageComposeViewController alloc] init] autorelease];
if([MFMessageComposeViewController canSendText])
{
controller.body = @"I am busy at the moment!";
controller.recipients = [NSArray arrayWithObject:@"Cell no"];
controller.messageComposeDelegate = self;
[self presentModalViewController:controller animated:YES];
[controller setSelectedScopeButtonIndex:1];
}
}

//Now you just have to call that function in your Button Action
//Just like:

-(IBACTION)ButtonSMSPressed
{
   [self SMSComposer];
}
finish.

No comments:

Post a Comment