gpt4 book ai didi

iphone - 电子邮件 Controller - 触摸取消时崩溃(但不发送)

转载 作者:行者123 更新时间:2023-11-29 11:19:24 25 4
gpt4 key购买 nike

我有一个非常简单的 MFMailComposeViewController 实现。它工作得很好——我从我的应用程序传递一个字符串,该字符串将通过电子邮件发送,然后触摸“发送”,电子邮件就会发送。没问题。

但是,如果我触摸“取消”按钮,应用程序将崩溃 (EXC_BAD_ACCESS)。我是否必须实现特殊方法来取消 MFMailComposeViewController?发送按钮会自动以正确的方式执行,但取消按钮不会。两者之间有什么区别(除了在一种情况下会发送电子邮件而在另一种情况下不会发送电子邮件)?

这是我的代码:

    #pragma mark - EMail

-(IBAction)emailCurrentPage:(id)sender {

NSString *textToBeSend = @"Test";

MFMailComposeViewController *mailComposer;

mailComposer=[[MFMailComposeViewController alloc] init];
mailComposer.mailComposeDelegate=self;
[mailComposer setMessageBody:textToBeSend isHTML:NO];
[self presentModalViewController:mailComposer animated:YES];

[mailComposer release];

}

- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error {

if (error) {

NSString *msgOFF = [[NSString alloc] initWithFormat:@"I could not send the e-mail for the following reason: %@", error];
UIAlertView *alertOFF = [[UIAlertView alloc]
initWithTitle:@"Error"
message:msgOFF
delegate:self
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alertOFF show];
[alertOFF release];
[msgOFF release];

}

[self dismissModalViewControllerAnimated:NO];


}

最佳答案

试试这个:

- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error  {   
NSString *message = @"";
// Notifies users about errors associated with the interface
switch (result) {
case MFMailComposeResultCancelled:
message = @"Mail: canceled";
break;
case MFMailComposeResultSaved:
message = @"Mail: saved";
break;
case MFMailComposeResultSent:
{
message = @"Mail: sent";

//Your code


}
break;
case MFMailComposeResultFailed:
message = @"Mail: failed";
break;
default:
message = @"Mail: not sent";
break;
}
[self dismissModalViewControllerAnimated:YES];
}

关于iphone - 电子邮件 Controller - 触摸取消时崩溃(但不发送),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8008283/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com