I want to know if it's possible to send email through iPhone simulator. I have seen the tutorial for sending an email through iphone as below:
http://www.edumobile.org/iphone/iphone-programming-tutorials/compose-mail-application-in-iphone/
Now to test it is it necessary to have real device? What is the way if I want to send email through iPhone simulator?
Yes, that's true. I always wondered if I can send a Push Notification on iOS simulator instead getting a real device while developing applications. Simulator supports simulating remote push notifications, including background content fetch notifications.
When in the simulator, hold the option key down and click - this will simulate a two-finger tap!
In Simulator, drag and drop an APNs file onto the target simulator. The file must be a JSON file with a valid Apple Push Notification Service payload, including the “aps” key. It must also contain a top-level “Simulator Target Bundle” with a string value matching the target application's bundle identifier.
You have to rely on the iOS that the MFMailComposeResult
that is handed back in mailComposeController:didFinishWithResult:error:
is correct. The simulator fakes that result; no actual mail is sent although it says MFMailComposeResultSent
.
The tutorial mentioned misses an important point: The first thing you should do before using MFMailComposeViewController
is to check [MFMailComposeViewController canSendMail]
. That will return NO
, if the user hasn't configured mail on their device. If you must support an iOS version prior to 3.0 the correct way is to check if the class MFMailComposeViewController
exists:
Class mailClass = (NSClassFromString(@"MFMailComposeViewController")); if (mailClass != nil) { if ([mailClass canSendMail]) { [self displayComposerSheet]; } else { [self launchMailAppOnDevice]; } } else { [self launchMailAppOnDevice]; }
The canSendMail-issue can only be tested on a real device though. It will crash if you don't check canSendMail and the user has no mail account configured.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With