如何关闭应用内ios文本消息的消息窗口

一旦短信窗口弹出,我无法让它再次关闭.取消按钮不起作用,发送按钮将发送短信但不关闭窗口.

我在这里看了很多类似的问题,他们都建议实现messageComposeViewController方法或者将messageComposeDelegate设置为self,但我已经完成了这两件事但仍然没有.

谁能告诉我我做错了什么?

.h文件

#import <MessageUI/MFMessageComposeViewController.h>
#import <MessageUI/MessageUI.h>
@interface ViewController : UIViewController<CLLocationManagerDelegate,MFMessageComposeViewControllerDelegate,UINavigationControllerDelegate>{
  CLLocationManager *locationManager;
  MKMapView *mapView_;

}

.m文件

- (IBAction)SendTextTapped:(id)sender{
    MFMessageComposeViewController *controller = [[MFMessageComposeViewController alloc] init];
    if([MFMessageComposeViewController canSendText])
    {
        controller.body = @"Hello!";
        controller.recipients = [NSArray arrayWithObjects:@"123456", nil];
        controller.messageComposeDelegate = self;
        [self presentViewController:controller animated:YES completion:nil];
    }
}


- (void)messageComposeViewController:(MFMessageComposeViewController*) controller didFinishWithResult:(MessageComposeResult)result error:(NSError*)error;
{
  NSLog(@"Entered messageComposeController");
  switch (result) {
    case MessageComposeResultSent: NSLog(@"SENT"); [self dismissViewControllerAnimated:YES completion:nil]; break;
    case MessageComposeResultFailed: NSLog(@"FAILED"); [self dismissViewControllerAnimated:YES completion:nil]; break;
    case MessageComposeResultCancelled: NSLog(@"CANCELLED"); [self dismissViewControllerAnimated:YES completion:nil]; break;
  }
}

最佳答案 删除委托方法上的error参数.委托方法应该是:

- (void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result {
    // code here
}

不:

- (void)messageComposeViewController:(MFMessageComposeViewController*) controller didFinishWithResult:(MessageComposeResult)result error:(NSError*)error
{
    // code here
}
点赞