我正在使用此代码崩溃
不支持推送导航控制器
MFMessageComposeViewController *messageController = [[MFMessageComposeViewController alloc] init];
messageController.messageComposeDelegate = self;
[messageController setRecipients:recipents];
[messageController setBody:message];
[self.parentViewController presentViewController:messageController animated:YES completion:nil];
答案 0 :(得分:4)
[self presentViewController:messageController animated:YES completion:nil];
答案 1 :(得分:1)
您的View是否在NavigationController堆栈中?试试这个 -
[self.navigationController presentViewController:messageController animated:YES completion:nil];
答案 2 :(得分:1)
如果您使用的是storyboard
或.xib
,则以下代码可以帮助您。
添加MessageUI.framework
为导入类编写此行。
#import <MessageUI/MessageUI.h>
设置委托
@interface ListViewController : UIViewController <MFMessageComposeViewControllerDelegate, UINavigationControllerDelegate>
实施以下方法
- (IBAction)sendMessage:(UIButton *)sender
{
if([MFMessageComposeViewController canSendText])
{
MFMessageComposeViewController *controller = [[MFMessageComposeViewController alloc] init];
controller.body = @"Hello...";
controller.recipients = [NSArray arrayWithObjects:@"recipient1, recipient2, recipient3", nil];
controller.messageComposeDelegate = self;
controller.delegate = self;
[self presentViewController:controller animated:YES completion:nil];
}
}
实现其解雇的委托方法
#pragma mark - Message Delegate ============================
- (void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result
{
switch (result)
{
case MessageComposeResultCancelled: break;
case MessageComposeResultFailed:
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"" message:@"Sorry, something went wrong, please try again." delegate:self cancelButtonTitle:@"OK" otherButtonTitles: nil];
[alert show];
}
break;
case MessageComposeResultSent: break;
default: break;
}
[[controller presentingViewController] dismissViewControllerAnimated:YES completion:nil];
}
答案 3 :(得分:0)
这是不可能的,因为docs说MFMessageComposeViewController
是UINavigationController
OC
@interface MFMessageComposeViewController : UINavigationController
迅速
class MFMessageComposeViewController : UINavigationController