I am having an Issue. I am attaching PDF Document to MFMailComposer. The issue is if i attach a PDF Document which contains only one page then When i am presenting the MFMailComposer, the attached PDF is opening and displaying. But, if i attach a PDF with more than one Page then it is displaying as icon.
If the pdf has one page or more number of pages i need to display as icon.
Could anyone please check it out !!!!
It should work in iPad
If it is the default functionality then please link with apple documents.
Sample Code :
MFMailComposeViewController *objMFMailComposeViewController = [[MFMailComposeViewController alloc] init];
if([MFMailComposeViewController canSendMail])
{
[objMFMailComposeViewController setMailComposeDelegate:self];
[objMFMailComposeViewController setSubject:[NSString stringWithFormat:#"Generated Reports for %#",lbl_details.text]];
NSString *path = [[NSBundle mainBundle] pathForResource:#"Material Details" ofType:#"pdf"];
NSData *myData = [NSData dataWithContentsOfFile:path];
[objMFMailComposeViewController addAttachmentData:myData mimeType:#"application/pdf" fileName:#"Material Details.pdf"];
[objMFMailComposeViewController setMessageBody:#"" isHTML:NO];
[self presentModalViewController:objMFMailComposeViewController animated:YES];
}
its is default functionality as you can try it by Email a Image from photo gallery. it shows image preview
Related
I am working on iPhone App similar to Pimp My text available here:
http://itunes.apple.com/us/app/pimp-my-text-send-color-text/id489972714?mt=8
I am trying to find a way for sending Colored and animated Messages as the app does.
I have tried this by using UIWebview but it seems the paste board is used in the app to send the iMessage but its not working. The paste board copies the message from editor screen of message and paste it to default iMessage controller. But I am not sure how it is done in the app.
Can anyone suggest any way to send the Colored, animated text with effects?
I have fixed this by following code:
UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
pasteboard.persistent = YES;
NSString *imagefile =app.strimagepath;
///
BOOL fileExists = [[NSFileManager defaultManager] fileExistsAtPath:imagefile];
if (fileExists)
{
NSData *data = UIImagePNGRepresentation([UIImage imageWithContentsOfFile:imagefile]);
pasteboard.image = [UIImage imageWithData:data];
}
NSString *phoneToCall = #"sms: 123-456-7890";
NSString *phoneToCallEncoded = [phoneToCall stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding];
NSURL *url = [[NSURL alloc] initWithString:phoneToCallEncoded];
[[UIApplication sharedApplication] openURL:url];
Here app.strimgPath is the path of image stored in document directory. when the MessageView is opened. Longpress and click on Paste and message will be pasted.
May be the question I asked did not clarified correctly as what I want. But the above was something that solved my purpose.
[SOLVED] Guess I should have RTFM! Using [MFMailComposeViewController addAttachmentData: mimeType: fileName:] solved my problem completely. No need for base64 encoding at all :)
For anyone whose interested this question provides some good information about base64 encoding.
I allow the user to take or choose an image and attach it to an email. The email sends and delivers perfectly well in Mac Mail but on Windows (Outlook Express & gmail) the image does not display. Gmail tells me 'The Conversion Cannot Be Loaded'.
Below is the code I use to attach the image to an email. It must eb something to do with the encoding of the image. Can anyone advise?
Many thanks for any help
- (void) createEmail {
// set up the image data.
NSData *imageData = [NSData dataWithData:UIImageJPEGRepresentation(self.imageToUpload, 1.0)];
NSString *base64String = [imageData base64EncodedString];
NSString *emailBodyString = [NSString stringWithFormat:#"<html><body><img src='data:image/jpeg;base64,%#'></body></html>",base64String];
// create the email modal
NSArray *recipients = [[NSArray alloc] initWithObjects:#"test#email.com",nil];
MFMailComposeViewController *emailDialog = [[MFMailComposeViewController alloc] init];
emailDialog.mailComposeDelegate = self;
[emailDialog setToRecipients:recipients];
[emailDialog setSubject:#"Time Sheet Submission from iPhone App"];
[emailDialog setMessageBody:emailBodyString isHTML:YES];
[self presentModalViewController:emailDialog animated:YES];
[emailDialog release];
[recipients release];
}
Guess I should have RTFM! Using [MFMailComposeViewController addAttachmentData: mimeType: fileName:] solved my problem completely. No need for base64 encoding at all :)
For anyone whose interested this question provides some good information about base64 encoding.
I am sending some images in mail using MFMailComposer. I am converting the image to Base64 and using <img> tag to add images to the HTML body(I am not adding it as attachment).
[htmlString appendFormat:
#"<img src='data:image/png;base64,%#' width=300 height=200 />", imageAsBase64];
The images are displaying correctly in MFMailComposer, but there are no images displayed in the actual mail which is sent from the MFMailComposer.
What should I do to make it work?
I had same problem before couple of weeks and I came to know that Gmail is not supporting embedded images. You can see images in email in other mail provider like your domain email but not in Gmail.
Try to send another email and you can see images. You need to add images as attachment then you can see images and it will display bottom of your email body.
Hope this help.
You have to add the images as an attachment. The rendered email that you see with HTML doesn't get rendered properly with the missing image URL.
here is an example: the caveat is that if you want to include things like a PDF you must include an image otherwise mfmailcomposer will fail... this in an apple bug.
I found the solution... Isubmitted a bug on Apple radar about it. MFMailcomposer has a bug in which you have to send an image along with your extra attachments in order to get the weird items like a pdf to work... try this and replace the pdf with your card:
MFMailComposeViewController *controller = [[MFMailComposeViewController alloc] init];
NSString *emailSubject = [NSString localizedStringWithFormat:#"MedicalProfile"];
[controller setSubject:emailSubject];
NSString *fileName = [NSString stringWithFormat:#"%#.pdf", profileName];
NSString *saveDirectory = NSTemporaryDirectory();
NSString *saveFileName = fileName;
NSString *documentPath = [saveDirectory stringByAppendingPathComponent:saveFileName];
*** YOU MUST INCLUDE AN IMAGE OR THE PDF ATTATCHMENT WILL FAIL!!!***
// Attach a PDF file to the email
NSData *pdfData = [NSData dataWithContentsOfFile:documentPath];
[controller addAttachmentData:pdfData mimeType:#"application/pdf" fileName:fileName];
// Attach an image to the email
NSString *imagePath = [[NSBundle mainBundle] pathForResource:#"miniDoc" ofType:#"png"];
NSData *imageData = [NSData dataWithContentsOfFile:imagePath];
[controller addAttachmentData:imageData mimeType:#"image/png" fileName:#"doctor"];
[controller setMessageBody:[NSString stringWithFormat:#"%#'s Medical Profile attatched!", profileName] isHTML:NO];
[self presentModalViewController:controller animated:YES];
controller.mailComposeDelegate = self;
[controller release];
I have my application sending an email, but is there a way to put a photo in my email above the text i'm sending. Kind of like a header to display my logo.
// Action for submenu Email Button
- (IBAction)emailButtonPressed {
[delegate playSound:#"Click_16"];
if (connectionStatus == YES)
{
if (maxCounter)
{
NSString *filename = (NSString *)[self currentImageObject:kSerialKey AtIndex:imageCounter];
NSString* documentsDirectory = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
// set up image data for email
NSString *imageFile = [documentsDirectory stringByAppendingPathComponent:filename];
NSData *imageData = [NSData dataWithContentsOfFile:imageFile];
// set up mail view controller for message
MFMailComposeViewController *controller = [[MFMailComposeViewController alloc] init];
if (controller != nil)
{
controller.mailComposeDelegate = self;
[controller setSubject:#"Email Subject"];
[controller setMessageBody:#"Check out this picture" isHTML:NO];
[controller addAttachmentData:imageData mimeType:#"image/png" fileName:filename];
[self presentModalViewController:controller animated:YES];
}
[controller release];
}
else
[self genericAlert:#"There are no pictures to email."];
}
else
[self genericAlert:#"You are not connected to the internet. Please connect and try again."];
}
// email delegate method to dismiss window
- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error {
[self becomeFirstResponder];
[self dismissModalViewControllerAnimated:YES];
}
When you attach an image using the MFMailComposeViewController it is always displayed at the bottom of the message (under your text, but above the signature) and this cannot be changed in the current version of the framework.
It is possible, however, to encode your image data into base64 and place this directly in the HTML body of your app. I won't include the code here (you can easily google it) because this is tricky and problematic since not all readers will interpret this correctly.
If this is a header image that will be the same for all emails you can put this on a server somewhere and then include an <img> tag in your HTML email body that references this file.
If this is a dynamic image you can have your app upload it to one of the many image hosting sites, retrieve the url and again include it as the src of an <img> tag in your HTML email body.
You should use the - (void)addAttachmentData:(NSData*)attachment mimeType:(NSString*)mimeType fileName:(NSString*)filename method from the MFMailComposeViewController class.
Here's a great example of this that shows taking an image from the camera and then sending it an an email message!
My PDF file appears in both UIWebView and the mail on screen on iphone as an attachment. When I send it to my email (using two different email carriers) it gets stripped out-no file attachment. I can send pdfs to these email accounts on my iphone and forward them ok so I don't think its my email provider but iOS that is stripping the file out??? I can attach images ok but NOT PDF files. Not sure where the issue is and how to find where the issue is occuring. Thanks!
My code:
-(void)doSendEmail :(NSString *)use_email :(NSString *)amsg {
if ([MFMailComposeViewController canSendMail]) {
MFMailComposeViewController* controller = [[MFMailComposeViewController alloc] init];
controller.mailComposeDelegate = self;
[controller setToRecipients:[NSArray arrayWithObjects:use_email, nil]];
NSString *filen=self.filepath1;
NSString *pdfPath = [[NSBundle mainBundle] pathForResource:filen ofType:#"pdf"];
NSData *pdfData = [NSData dataWithContentsOfFile:pdfPath];
[controller addAttachmentData:pdfData mimeType:#"application/pdf" fileName:self.filename1]
}
//Set messages
[controller setSubject:self.subject];
[controller setMessageBody:amsg isHTML:NO];
//Display email for user to send
[self presentModalViewController:controller animated:YES];
[controller release];
}
-(void)mailComposeController:(MFMailComposeViewController*)controller
didFinishWithResult:(MFMailComposeResult)result
error:(NSError*)error {
if ( (result == MFMailComposeResultSent) && (stat==4) ) {
billsent=1;
}
[self dismissModalViewControllerAnimated:YES];
}
This is an old question but I came across it in my google searches so I thought I'd post my solution:
It is likely that your pdfPath is wrong. If the pdf is loaded as an attachment properly you should not see an icon for the attachment. Instead you will see a large image of the pdf itself.
If you set a break point right after NSData *pdfData = and hover over pdfData it will probably show you that it is nil with 0 bytes of data.