別の StackOverflow 投稿から: ( 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
ただし、バックグラウンドで SMS メッセージを送信することはできません。これが役立つことを願っています。