【发布时间】:2026-02-06 02:15:02
【问题描述】:
我发现自己遇到了一个非常奇怪的问题。在我们正在开发的应用程序中,有一个功能可以从应用程序本身发送邮件。
根据 Xamarin 配方,MFMailComposeViewController 是适用于 Xamarin.ios 的方式。
https://developer.xamarin.com/recipes/ios/shared_resources/email/send_an_email/
似乎只有部分设备存在问题,但我不清楚这种模式。
按下“发送”或“取消”按钮时,将调用 Finished 委托。这部分通常应该关闭 MailViewController。
在某些设备上,行为符合预期,邮件控制器从屏幕上移除,并显示底层控制器。 然而,在某些设备上,邮件控制器保持在顶部,并且应用程序不再响应。调试器不显示任何内容。
到目前为止,有人遇到过这个问题吗?这能以某种方式解决吗?我正在阅读 obj-c 或 swift 代码中的一些类似行为,但是他们的解决方案对我没有帮助。
MFMailComposeViewController in Swift does not dismiss
这是我的代码:
private void OnSendMailClick(object sender, EventArgs e)
{
if (MFMailComposeViewController.CanSendMail)
{
string receiptText = trx.isReversed ?
Utilities.GetTransactionAndRefundReceipt(trx, manager) : Utilities.GetReceipt(trx, true);
var mailController = new MFMailComposeViewController();
mailController.SetSubject(String.Format("Receipt number: {0}", trx.STAN));
mailController.SetMessageBody(receiptText, true);
mailController.Finished += OnSendResult;
PresentViewController(mailController, true, null);
}
}
完成的委托看起来像这样:
private void OnSendResult(object sender, MFComposeResultEventArgs e) => e.Controller.DismissViewController(true, null);
编辑
原来问题出在 MFMalComposeViewController 的继承上,它是由 UINavigationViewController 继承的。 由于我已经在使用底层 UINavigationcontroller 这有时会导致问题。一旦找到合适的解决方案,我将在此处发布作为答案。
【问题讨论】:
标签: c# xamarin xamarin.ios