Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Duncan C

macrumors 6502a
Original poster
Jan 21, 2008
853
0
Northern Virginia
I'm working on a an app for a client that uses an MFMailComposeViewController.

I have written code that SHOULD detect an error in sending and display a localized message to the user that includes the localizedDescription from the NSError returned to the – mailComposeController:didFinishWithResult:error: method.

I want to test error handling throughly.

Is it possible to set up mail on the simulator? (iOS 6.1 running under Xcode 4.6.3)

I'd like to test various invalid cases, and would prefer not to bugger the email accounts on my other devices.

I don't see a mail settings page in the settings panel. Oddly, I don't get an error when I try to send - it just sends and the outgoing mail seems to be dropped into the "bit bucket".
 

ArtOfWarfare

macrumors G3
Nov 26, 2007
9,560
6,059
Maybe you should use a mail framework instead?

I've been using mailcore2 in an iOS email project I'm working on.
 

PhoneyDeveloper

macrumors 68040
Sep 2, 2008
3,114
93
I've never heard of a way to send email from the Sim.

I probably wouldn't depend on the localizedDescription from a system provided error object. They're mostly meant for developers.
 

xArtx

macrumors 6502a
Mar 30, 2012
764
1
It does work.
The email is "sent" if it is sent to the stock email app, not necessarily sent over the air at that time.
You can also check that email is enabled which means the device supports email && the user has an account set up on that device.
In any case the composed email doesn't make it to the stock email app is an
error, including if the user cancelled.

You would be talking about this:
Code:
		case MFMailComposeResultCancelled:
            //	message.text = @"Result: canceled";
            emailstatms = 1;
			break;
		case MFMailComposeResultSaved:
            //	message.text = @"Result: saved";
            emailstatms = 2;
			break;
		case MFMailComposeResultSent:
            //	message.text = @"Result: sent";
            emailstatms = 3;
			break;
		case MFMailComposeResultFailed:
            //	message.text = @"Result: failed";
            emailstatms = 4;
			break;
		default:
            //	message.text = @"Result: not sent";
            emailstatms = 5;
			break;
	}

See how I commented the error codes? I wanted to use my own creative descriptions:
Code:
    if (emailstatms == 1) {
    sprintf(text, "Email Cancelled");
    }
    if (emailstatms == 2) {
    sprintf(text, "Email Saved");
    }
    if (emailstatms == 3) {
    sprintf(text, "Email Sent");
    }
    if (emailstatms == 4) {
    sprintf(text, "Email Failed");
    }
    if (emailstatms == 5) {
    sprintf(text, "Email Not Sent");
    }


before sending, you can check the device has an account set up:

Code:
-(void)sendEmail{
    Class mailClass = (NSClassFromString(@"MFMailComposeViewController"));
	if (mailClass != nil)
	{
    if ([mailClass canSendMail]){[self displayComposerSheet];}
	} else {emailopen = 0;}
}
 
Last edited:
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.