gpt4 book ai didi

ios - 单击“取消”按钮时,“邮件撰写”不消失

转载 作者:行者123 更新时间:2023-12-01 18:13:50 26 4
gpt4 key购买 nike

我有这段代码,他们使用MFMailCompose向用户发送电子邮件:

.h文件

#import <UIKit/UIKit.h>
#import <MessageUI/MessageUI.h>
#import <MessageUI/MFMailComposeViewController.h>

@interface TestViewController : UIViewController <MFMailComposeViewControllerDelegate, MFMessageComposeViewControllerDelegate>

@property(nonatomic,assign) id<MFMailComposeViewControllerDelegate> mailComposeDelegate;

.m文件
@synthesize mailComposeDelegate

-(void)sendEmail:(NSString*)valor{

//Valor receive the email

NSString *corpoMensagem = @"No have body yet...";

// From within your active view controller
if([MFMailComposeViewController canSendMail]) {
MFMailComposeViewController *mailCont = [[MFMailComposeViewController alloc] init];
mailCont.mailComposeDelegate = self;// Required to invoke mailComposeController when send

[mailCont setSubject:@"FazerBem - Recibo de Compra"];
[mailCont setToRecipients:[NSArray arrayWithObject:valor]];
[mailCont setMessageBody:corpoMensagem isHTML:YES];

[self presentViewController:mailCont animated:YES completion:nil];
}

}

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

if (error){
NSString *errorTitle = @"Erro to send";
NSString *errorDescription = [error localizedDescription];
UIAlertView *errorView = [[UIAlertView alloc]initWithTitle:errorTitle message:errorDescription delegate:self cancelButtonTitle:nil otherButtonTitles:@"OK", nil];
[errorView show];
}

[self becomeFirstResponder];
[self dismissViewControllerAnimated:YES completion:nil];
}

-(void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result{


}

当我单击“发送”按钮时,他可以将电子邮件发送给收件人并可以关闭屏幕,现在,当我单击“取消”按钮时,当我单击其中一个应用程序时,它将打开2个选项“删除草稿”和“保存草稿”崩溃并返回以下错误:
[TestViewController respondsToSelector:]: message sent to deallocated instance 0x16b3b470

我该如何解决这个问题?

最佳答案

使用“切换到”来执行操作:

- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error
{
UIAlertView *alert;
switch (result)
{
case MFMailComposeResultCancelled:
break;
case MFMailComposeResultSaved:
alert = [[UIAlertView alloc] initWithTitle:@"Draft Saved" message:@"Composed Mail is saved in draft." delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil, nil];
[alert show];
break;
case MFMailComposeResultSent:
alert = [[UIAlertView alloc] initWithTitle:@"Success" message:@"You have successfully referred your friends." delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil, nil];
[alert show];
break;
case MFMailComposeResultFailed:
alert = [[UIAlertView alloc] initWithTitle:@"Failed" message:@"Sorry! Failed to send." delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil, nil];
[alert show];
break;
default:
break;
}

// Close the Mail Interface
[self dismissViewControllerAnimated:YES completion:nil];
}

关于ios - 单击“取消”按钮时,“邮件撰写”不消失,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24981994/

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