views:

159

answers:

2

Hi,

I'm using a MFMailComposeViewController in my iphone app and I'd like to give the user the choice to attach some pictures to the e-mail.

As there is no specific button by default, I was thinking about subclassing MFMailComposeViewController and adding a button for this. Unfortunately, according to the documentation the addAttachmentData: method shouldn't be called once the view has been displayed, so the choice can not be made during the mail composition.

I also thought about creating my own mail composer view, but according to this question: http://stackoverflow.com/questions/1263412/send-mail-without-mfmailcomposeviewcontroller , Apple does not want developers to do this as this could be used to abuse the user's mail account.

So, it seems the only solution is to ask the user prior to showing up MFMailCompose, and the only way for the user to change his choice would be to cancel mail composition and start it again, am I right?

+1  A: 

When user tap the attach button, dismiss the MFMailComposeViewController and open the image picking controller. When the image is picked, create a new MFMailComposeViewController with the previous content and the new image as attachment.

I have not tried this. You can give a try.

Anil Sivadas
Good idea. I'll give it a try indeed, I'll just hope dismissing and creating a new controller instantly will not create any weird graphical effect.
Jukurrpa
was there any graphical effect problem? did it work on device?
Anil Sivadas
In fact, I finally chose a simpler way: a UIAlertView asks to the user if he wants to add pictures as attachment before the mail compose view shows up. He'll have to go back if he changes his mind, but the content of the mail makes this very unlikely.
Jukurrpa
A: 

Self answer: for me, the simplest way was to add a UIAlertView asking the user wether he wants to add the images or not, prior to showing up the mail composer view. This is adequate as all images should be sent together (so it's all or none), but for more elaborate cases (chose some images from the iphone for example), Anil Sivadas' answer might be a solution.

Jukurrpa