AmirZ
AmirZ

Reputation: 401

how can i cause a MFMailComposeResultFailed error

I want to test a certain behaviour I made for when email sending failed, but I can't get MFMailComposeResultFailed error. even when there is no internet connection, it still "sends" the email. how can this be done?

Upvotes: 0

Views: 265

Answers (1)

charlyatwork
charlyatwork

Reputation: 1197

This is not possible, hence this kind of "errors" will not be delivered by the delegate. An this make sense, because "Mail" takes care of sending or queuing the Mails.

From the docs (MFMailComposeViewController)

Using this interface does not guarantee immediate delivery of the corresponding email message. The user may cancel the creation of the message, and if the user does choose to send the message, the message is only queued in the Mail application outbox. This allows you to generate emails even in situations where the user does not have network access, such as in airplane mode. This interface does not provide a way for you to verify whether emails were actually sent.

You could check the internet connection before displaying the MFMailComposeViewController. This is technical possible but not recommended. Mail will automatically send the mail if the device is connected to the internet again.

But you have to check if the device is configured to send a mail:

if ([MFMailComposeViewController canSendMail]){
 //show MFMailComposeViewController
}else{
 //show AlertView
}

Before using this class, you must always check to see if the current device is configured to send email at all using the canSendMail method. If the user’s device is not set up for the delivery of email, you can notify the user or simply disable the email dispatch features in your application. You should not attempt to use this interface if the canSendMail method returns NO.

https://developer.apple.com/library/ios/documentation/MessageUI/Reference/MFMailComposeViewController_class/#//apple_ref/c/tdef/MFMailComposeResult

Upvotes: 1

Related Questions