pythonquick pythonquick - 1 year ago 130
Objective-C Question

When will [MFMailComposeViewController canSendMail] return NO

My iPhone app is using the MFMailComposeViewController class to send an in-app email with an attachment.
The app will only attempt to display the mail composer dialog if the "canSendMail" method of class MFMailComposeViewController returns true (YES). Specifically, if the following method returns YES, it shows the mail composer, otherwise the user is presented with an error alert dialog stating that there are no email accounts set up on the device:

- (BOOL)canDeviceSendEmail
Class mailClass = (NSClassFromString(@"MFMailComposeViewController"));
return mailClass != nil && [mailClass canSendMail];

A team of testers have reported that they get this error alert dialog, even when email accounts are set up on the device. The tester used an iPhone 3G with OS 3.1.3. Therefore the MFMailComposeViewController class must have existed, and the "canSendMail" method must have returned NO.

My question is therefore: apart from the case when there are no email accounts set up on the device, in what other circumstances can the "canSendMail" method return NO?

~ Thanks

Answer Source

If at least one email account is enabled on the device, the following call should return YES:

[MFMailComposeViewController canSendMail]

Conversely, if all accounts are disabled/removed, it will return NO.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download