【问题标题】:MFMailComposeViewController navigation bar buttons are disabledMFMailComposeViewController 导航栏按钮被禁用
【发布时间】:2023-04-01 10:57:02
【问题描述】:
我使用 MFMailComposeViewController 在我的应用程序中发送邮件。但是当存在邮件撰写视图控制器时,所有导航按钮都被禁用(选择邮件地址屏幕中的后退按钮除外),我必须使用主页按钮退出应用程序。有人有想法吗?
这是屏幕截图:
代码:
- (void)shareVieEmail
{
if ([MFMailComposeViewController canSendMail]) {
MFMailComposeViewController *mailViewController = [[MFMailComposeViewController alloc] init];
mailViewController.mailComposeDelegate = self;
[mailViewController setSubject:@"测试主题"];
[mailViewController setMessageBody:@"邮件正文" isHTML:NO];
NSData *imageData = [NSData dataWithContentsOfFile:photourl];
[mailViewController addAttachmentData:imageData mimeType:@"image/jpg" fileName:@"example_photo"];
[自我presentModalViewController:mailViewController动画:YES];
} 别的 {
[[[UIAlertView alloc] initWithTitle:@"Cannot send mail" message:@"Device is unable to send email in its current state" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil] show];
}
}
委托方法:
- (void)mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error
{
切换(结果)
{
案例 MFMailComposeResultCancelled:
//NSLog(@"结果:取消");
休息;
案例 MFMailComposeResultSaved:
//NSLog(@"结果:保存");
休息;
案例 MFMailComposeResultSent:
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Result" message:@"Mail Sent Successfully" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
[警报显示];
}
休息;
案例 MFMailComposeResultFailed:
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Result" message:@"Mail Sent Failed" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
[警报显示];
}
休息;
默认:
//NSLog(@"结果:未发送");
休息;
}
如果(错误){
[[[UIAlertView alloc] initWithTitle:@"Cannot send mail" message:[NSString stringWithFormat:@"ERROR:%@", [error userInfo]] delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil] 显示] ;
}
[自我dismissModalViewControllerAnimated:是];
}
在头文件中,我声明了实现 MFMailComposeViewControllerDelegate。
【问题讨论】:
-
-
奇怪,看起来不错。这可能与您的电子邮件设置有关吗?在所有设备上都这样吗?
-
@mvds,它发生在模拟器和设备上。 Apple 的示例项目运行良好。
-
您是否知道每次呈现MFMailComposeViewController 的实例时都会泄漏?如果第一个实例以某种方式持有某种锁,从而阻止第二个实例获取一个锁,则可能会出现问题。在某处添加一行[mailer autorelease];,删除应用并重新安装。
-
目前,我使用 ARC 支持来编译项目(编码时不需要自动释放,保留,..),我认为这不是根本原因。但是,我会尝试只编译这个不支持 ARC 的文件。
标签:
iphone
objective-c
button
sendmail