Anybody no to send sms programmatically in iOS6
.Earlier I was using core telephony method to send SMS.It's working fine up to iOS5
but on iOS6
my code is not working.
I using following code:
BOOL success = [[CTMessageCenter sharedMessageCenter] sendSMSWithText:@"Message" serviceCenter:nil toAddress:@"8800781656"];
What am I doing wrong?
Thanks in advance
I would make an educated guess that Apple has closed a loop hole in their API. They do not want applications to send SMS message in the background without the user knowledge. On some mobile network each SMS message cost money.
// in .m file
-(void)textClicked
{
controller = [[MFMessageComposeViewController alloc] init];
if([MFMessageComposeViewController canSendText])
{
controller.body = @"Whatever you want";
controller.recipients = [NSArray arrayWithObjects:@"", nil];
controller.messageComposeDelegate = self;
[self presentViewController:controller animated:YES completion:nil];
}
}
- (void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"MyApp" message:@"Unknown Error"
delegate:self cancelButtonTitle:@"OK" otherButtonTitles: nil];
switch (result) {
case MessageComposeResultCancelled:
NSLog(@"Cancelled");
[alert show];
break;
case MessageComposeResultFailed:
[alert show];
break;
case MessageComposeResultSent:
break;
default:
break;
}
[self dismissViewControllerAnimated:YES completion:nil];
}
// in .h file
import MessageUI/MessageUI.h
and delegate for Sending Message is MFMessageComposeViewControllerDelegate
Hope , This will help You.