MFMessageComposeViewController不会在ios8上显示发送按钮和消息正文

时间:2015-09-24 09:19:40

标签: objective-c iphone ios8

MFMessageComposeViewController在ios8上没有显示发送按钮和消息正文,当点击收件人列表键盘出现并发送按钮时,消息体显示出来。以下是消息功能的代码:

MFMessageComposeViewController *msgController = [[MFMessageComposeViewController alloc] init] ;
if([MFMessageComposeViewController canSendText])
{
     if (msgController)
      {
           msgController = nil;
           msgController = [[MFMessageComposeViewController alloc] init] ;
      }
NSString *messageBody =@"helloWorld";
msgController.body = messageBody;
msgController.recipients = numberArray;
msgController.messageComposeDelegate = (id)self;
[self presentViewController:msgController animated:YES completion:^{}];

提前致谢。

2 个答案:

答案 0 :(得分:1)

首先将MessageUI框架添加到您的应用程序框架,然后

#import <MessageUI/MessageUI.h>
@interface class() 
<MFMailComposeViewControllerDelegate>
{
....
}
@end

然后在你的类实现中写

     if ([MFMailComposeViewController canSendMail])
     {
         MFMailComposeViewController *mail = [[MFMailComposeViewController alloc] init];
         [mail setMailComposeDelegate:self];
         [mail setSubject:@"Subject goes here..."];
         [mail setMessageBody:@"Message body goes here..." isHTML:NO];
         [self presentViewController:mail animated:YES completion:NULL];
     }

并实现MFMailcomposeViewController的委托,如

- (void)mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error {
    [controller dismissViewControllerAnimated:YES completion:nil];
}

答案 1 :(得分:0)