次の方法を使用します。
// .h ファイルにデリゲートを追加
@interface ContactsViewController : UIViewController<MFMessageComposeViewControllerDelegate>
// これを .m ファイルに追加します
MFMessageComposeViewController *picker = [[MFMessageComposeViewController alloc] init];
if(picker) {
picker.messageComposeDelegate = self;
picker.recipients = [NSArray arrayWithObject:number];
picker.body = @"body content";
[self presentViewController:picker animated:NO completion:nil];
picker = nil;
}
NSLog(@"SMS fired");
- (void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result {
switch (result)
{
case MessageComposeResultCancelled:
NSLog(@"Result: canceled");
break;
case MessageComposeResultSent:
NSLog(@"Result: sent");
break;
case MessageComposeResultFailed:
NSLog(@"Result: failed");
break;
default:
NSLog(@"Result: not sent");
break;
}
//[self dismissModalViewControllerAnimated:YES];
[self dismissViewControllerAnimated:YES completion:nil];
}