2012-03-25 123 views
0

我已经在我的代码中实现了MFMessageComposeViewController,但是现在我可以发送电子邮件了,当保存草稿,删除它或甚至发送电子邮件时,视图控制器不会被解雇。我也尝试添加断点,解除它的代码甚至无法运行。MFMailComposeViewController没有被解雇

- (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:@"[email protected]"]; 

[picker setEditing:YES]; 
[picker setToRecipients:toRecipients]; 

[self presentModalViewController:picker animated:YES]; 
picker.mailComposeDelegate = self; 
} 

- (void)launchMailAppOnDevice 
{ 
NSString *address = @"mailto:[email protected]"; 

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

尝试在调用presentModalViewController之前设置委托。

0

尝试在呈现模态视图之前设置picker.mailComposeDelegate = self。 它可能会帮助你。

+0

我这样做了,但无法将其设置为回答。不管怎么说,还是要谢谢你! – user1222053 2012-03-27 19:03:43