我已经在我的代码中实现了MFMessageComposeViewController,但是我现在可以发送电子邮件,在保存草稿,删除草稿甚至发送电子邮件时,视图控制器都不会被解雇。我也尝试过添加断点和代码来解雇它甚至不会运行。
- (IBAction)sendEmail:(id)sender {
Class mailClass = (NSClassFromString(@"MFMailComposeViewController"));
if(mailClass != nil)
{
if ([mailClass canSendMail])
{
[self displayComposerSheet];
}
else
{
[self launchMailAppOnDevice];
}
}
else
{
[self launchMailAppOnDevice];
}
}
- (void)displayComposerSheet
{
MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
NSArray *toRecipients = [NSArray arrayWithObject:@"foomail@foo.foo"];
[picker setEditing:YES];
[picker setToRecipients:toRecipients];
[self presentModalViewController:picker animated:YES];
picker.mailComposeDelegate = self;
}
- (void)launchMailAppOnDevice
{
NSString *address = @"mailto:enquiries@moray.it";
NSString *email = [NSString stringWithFormat:@"%@", address];
email = [email stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:email]];
}
-(void)mailComposeController:picker didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error
{
[self dismissModalViewControllerAnimated:YES];
}
答案 0 :(得分:0)
在调用presentModalViewController之前尝试设置委托。
答案 1 :(得分:0)
在展示模态视图之前尝试设置picker.mailComposeDelegate = self
。
它可能会帮助你。