4

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

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

1 回答 1

2

删除委托方法上的错误参数。委托方法应该是:

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

不是:

- (void)messageComposeViewController:(MFMessageComposeViewController*) controller didFinishWithResult:(MessageComposeResult)result error:(NSError*)error
{
    // code here
}
于 2013-03-13T19:54:21.560 回答