关闭 MFMailComposeViewController 的正确方法
我已经无计可施了。当我的应用程序转换到后台时,我需要关闭 MFMailComposeViewController ,但我无法做到这一点。它最终会创建一个尴尬的应用程序状态。
有没有办法以编程方式处理这个问题?也许强制视图控制器将电子邮件放入草稿文件夹并在没有动画的情况下关闭?
编辑:
对 -dismissModalViewControllerAnimated:
的调用无法按预期工作。
我所说的尴尬的应用程序状态是当应用程序从后台返回时,我的主视图在电子邮件编辑器之上重新绘制。该模式永远不会被关闭,并且该电子邮件编辑器永远无法再次访问。
编辑:
我的初始化程序中的代码:
// For compatibility with iOS versions below 4.0
if (&UIApplicationDidEnterBackgroundNotification != NULL)
{
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationDidEnterBackgroundNotification:) name:UIApplicationDidEnterBackgroundNotification object:nil];
}
我的后台条目处理程序中的代码:
- (void) applicationDidEnterBackgroundNotification:(NSNotification *)note {
// Do some other stuff here
// According to the docs, calling the method like this closes all
// child views presented modally
[self dismissModalViewControllerAnimated:NO];
}
I'm at my wit's end. I need to dismiss an MFMailComposeViewController
when my app transitions to the background and I can't do it. It ends up creating an awkward application state.
Is there a way to handle this programmatically? Perhaps force the view controller to put the email into the Drafts folder and dismiss without animating?
EDIT:
Calls to - dismissModalViewControllerAnimated:
don't work as expected.
The awkward application state I'm talking about is my main view being redrawn over top of the email composer when the application returns from the background. The modal is never dismissed and that email composer is never accessible again.
EDIT:
Code in my initializer:
// For compatibility with iOS versions below 4.0
if (&UIApplicationDidEnterBackgroundNotification != NULL)
{
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationDidEnterBackgroundNotification:) name:UIApplicationDidEnterBackgroundNotification object:nil];
}
Code in my background-entry handler:
- (void) applicationDidEnterBackgroundNotification:(NSNotification *)note {
// Do some other stuff here
// According to the docs, calling the method like this closes all
// child views presented modally
[self dismissModalViewControllerAnimated:NO];
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我用上面的代码复制了一个简单的应用程序。当应用程序进入后台时,邮件编辑器将被正确关闭。
因此,我只能假设代码的
//Do some other stuff here
部分做了太多的事情,并且操作系统在您有机会解雇作曲家之前关闭了您。根据 文档:
也许您应该将其他内容移至不同的线程或请求额外的时间?如果你删除其他东西,作曲家是否正确地驳回?
I have reproduced a simple application with the code you have above. The mail composer is dismissed properly when the application enters the background.
I can only assume therefore that the
//Do some other stuff here
section of your code is doing too much stuff and the OS is shutting you down before you have chance to dismiss the composer.According to the docs:
Perhaps you should move your other stuff to a different thread or request extra time? If you remove the other stuff, does the composer dismiss correctly?