MFMailComposeViewController canSendMail doesn't return right value in specific scenario

1.3k views Asked by At

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?

0

There are 0 answers