April 2014 update: we have moved the project and packaged it with a sleek manual on our new website, along with a sleek manual and demo video. Check it out: http://easynativeextensions.com/product/diadraw-e-mail-ane/

Good morning/afternoon/fill in your timezone, AIR people!

A lot of you got in touch to tell us that the release of iOS 7 broke our e-mail ANE and asked if we could fix that.

We let most of you in on a little secret: we are preparing updates for all of our native extensions, including the e-mail one, to release on a brand new website. The website, http://easynativeextensions.com/, is dedicated to making cross-platform development dead easy and we have a few more new extensions in the bag to release on it. But, as I said, it’s a secret, so tell no one.

While the website is in development and still a couple of weeks away from seeing daylight, we thought we would get the e-mail ANE fix to you in the meantime, because we understand it sucks to have a buggy app in the App Store.

The problem

On iOS 7 the mail composer gets stuck and won’t go away after you have sent an e-mail or have tapped Cancel. You have to restart your app to make it go away. What’s worse, your users have to do it too.

If this describes the pain you are having, read on.

The fix

I’m going to tell you where the problem is in the native code and how to fix it.

That’s all very good, but could I download the ANE first?

April 2014 update: we have moved the project and packaged it with a sleek manual on our new website, along with a sleek manual and demo video. Check it out: http://easynativeextensions.com/product/diadraw-e-mail-ane/

And if you don’t want to go through the shenanigans of finding where to apply the fix, rebuild and repackage the ANE, I can’t blame you.

And now the fix

For all of you badasses out there who have built your own ANE from our code, here is how to fix it.

The problem seems to be that in iOS 7 the root view controller of the application loses track (i.e. loses the reference to) the mail controller we have asked it to present with this call:

[[[[UIApplication sharedApplication] keyWindow] rootViewController] presentViewController: mailComposer animated: YES completion: NULL];

So the next call, which worked on previous iOS versions, doesn’t do much any more:

[[[[ UIApplication sharedApplication] keyWindow] rootViewController] dismissViewControllerAnimated: YES completion:^{ [ self notifyMailComposerDismissed ]; }];

Luckily for us, mailComposer remembers who presented it, so calling this instead works:

[[ mailComposer presentingViewController ] dismissViewControllerAnimated: YES completion: ^{ [ self notifyMailComposerDismissed ]; }];

To be able to make this call at the point where the user has tapped Send or Cancel, we’ll have to keep a reference to mailComposer. And, of course, tidy it up when we are done with it.

That’s it.

About the Author

Radoslava is co-founder of DiaDraw. Prefers to communicate with images. Verbal communication always caused trouble with her parents. Started speaking Basic early on, followed by four years of Delphi, six years of C++, four years of ActionScript, lately converses in Objective-C. Her mum and dad hope she'll start speaking human at some point.