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

时间:2013-03-13 19:42:14

标签: ios ios6 sms messageui mfmessagecomposeview

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

我在这里看了很多类似的问题,他们都建议实现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;
  }
}

1 个答案:

答案 0 :(得分:2)

删除委托方法的error参数。委托方法应为:

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

NOT:

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