Reputation: 963
Has anyone managed yet to send an SMS from code without user interaction in iOS 6?
I think, the ChatKit private API has to be used to do this. However, it seems that Apple changed this API quite a lot in iOS 6. As a result, solutions like https://stackoverflow.com/a/11028230/1884907 don't work anymore on iOS 6 because of missing/changed classes.
(just in advance: yes, we all know that Apple rejects apps with private API, it's not for the app store)
Upvotes: 3
Views: 3044
Reputation: 2196
From another StackOverflow post here: (Code from Kaushal Bisht)
// 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
You can't send SMS messages in the background though. I hope this helps.
Upvotes: 1