I have searched around the internet and stack and have not quite found the right answer for my conditions. ( Xcode 4.2, iOS 5, ARC, LLDB, Storyboard, Universal App )
Looking for the method to allow users the option to select a photo to add to the email.
I want to keep it non-obtrusive and add a button within MFMailComposeViewController that allows users to add a photo from their photo library or take a photo with their camera.
I tried to using a button to viewController with UIImpagePicker and Camera on view controller that added image to UIImageView with a separate mail function button, but this was overkill and clutter the app unnecessarily, I also was unable to figure out the to code to insert the chosen photo into the email.
My inapp email works perfectly, here is the code
.h
#import <MessageUI/MessageUI>
<MFMailComposeViewControllerDelegate>
.m
- (IBAction)Email:(id)sender
{
if ([MFMailComposeViewController canSendMail]) {
MFMailComposeViewController *mail = [[MFMailComposeViewController alloc] init];
mail.mailComposeDelegate = self;
[mail setSubject:@"Feedback"];
NSArray *toRecipients = [NSArray arrayWithObjects:@"feedback", nil];
[mail setToRecipients:toRecipients];
NSString *emailBody = @"-Your Message Here-";
[mail setMessageBody:emailBody isHTML:NO];
mail.modalPresentationStyle = UIModalPresentationPageSheet;
[self presentModalViewController:mail animated:YES];
} else {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error:"
message:@"E-mail is not supported on your device."
delegate:nil
cancelButtonTitle:@"Cancel"
otherButtonTitles:nil];
[alert show];
}
}
The mail composer doesn't offer the ability to add user selected photos itself and adding controls to the composer view controller isn't recommended.
You'll have to make the user choose the photo first using UIImagePickerController and then add it as an attachment when you present the mail composer.
The question is not how to code it, but rather how to design the UI. Maybe you could make it a little bit like the twitter app handles various attachment and additional information.
Fabian