MFMailComposeViewController canSendMail 在特定情况下不返回正确的值

发布于 2024-12-27 02:37:05 字数 1160 浏览 2 评论 0原文

我发现在创建/删除邮件帐户后,[MFMailComposeViewController canSendMail] 在从后台唤醒应用程序时返回错误的值。

在我的应用程序中,有一些功能仅在邮件可用时才相关。因此我想禁用将其与 canSendMail 检查一起使用的可能性。

一切正常,而不是以下情况: 1.删​​除/禁用iPhone上的邮件帐户(现在我正在使用iOS 4.2进行工作和测试) 2. 启动应用程序 - 所有内容均以正确的方式禁用。 3. 按主页按钮并打开“设置”。创建并设置邮件帐户。 4. 返回应用程序 - [MFMailComposeViewController canSendMail] 返回 NO,但已设置邮件帐户。 5. 按主页按钮,然后再次返回应用程序 - [MFMailComposeViewController canSendMail] 返回 YES,正如应该的那样。

此外,反之亦然,当我们打开应用程序,转到设置,删除邮件帐户,返回应用程序时,此行为是可重现的 - canSendMail 在删除后打开第一个应用程序时返回“是”,而在第二个应用程序中返回“否”。

我正在 ApplicationDelegate 的 - (void)applicationWillEnterForeground:(UIApplication *)application 函数中检查 [MFMailComposeViewController canSendMail]

在我看来, MFMailComposeViewController 存储值,并且有一些事件迫使它重新读取邮件可用性。另外,我尝试在正确的线程上添加一些等待(1-2秒),或者在邮件设置和运行我的应用程序之间运行其他应用程序 - 没有任何帮助。

您对我如何获得 canSendMail 的正确价值有什么想法吗?否则,唯一的方法就是杀死发现这个 bug 的 QA...


而且下面的代码也不起作用。

Class mailClass = (NSClassFromString(@"MFMailComposeViewController")); 
if (mailClass != nil) 
{ 
    return [mailClass canSendMail]; 
} 
return NO;

有什么建议吗?

I found that [MFMailComposeViewController canSendMail] returns wrong value on application wake up from background after mail account was created/deleted.

In my application there's some functionality that is relevant only when mailing is available. Thus I want to disable possibility to use it with canSendMail checking.

All works well instead of the following scenario:
1. Delete/disable mail account on iPhone (now I'm working and test with iOS 4.2)
2. Start application - all stuff is disabled in correct way.
3. Press Home button and open Settings. Create and setup mail account.
4. Return to application - [MFMailComposeViewController canSendMail] returns NO, but mail account was setup.
5. Press Home Button and then back to application again - [MFMailComposeViewController canSendMail] returns YES, as should.

Also, this behavior is reproducible vise-versa, when we open application, go to settings, delete mail account, back to application - canSendMail returns YES for first application opening after deletion and NO, as should, on second one.

I'm checking [MFMailComposeViewController canSendMail] at ApplicationDelegate's - (void)applicationWillEnterForeground:(UIApplication *)application function.

It seems to me that MFMailComposeViewController store value and there's some event that force it to re-read mail availability. Also I tried to add some waiting (1-2 seconds) on proper thread, or run other application between mail setup and run my app - nothing helps.

Do you have any ideas on how I could get right value for canSendMail? Otherwise, the only way is to kill QA who found this bug...


Also the following code doesn't work too.

Class mailClass = (NSClassFromString(@"MFMailComposeViewController")); 
if (mailClass != nil) 
{ 
    return [mailClass canSendMail]; 
} 
return NO;

Any suggestion?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文