I have an APP to share people's photos to Mail, but on iPhone 6 Plus, I found it's preview image sometimes got cut, like this :
Image link is here:
Broken Image
In fact, there is a string like "Send from my phone" after image, it is cut too.
But if I move cursor to the end of the image, and press return on the keyboard, the image and "Send from my phone" become intactness.
I'm sorry, I can't send image directly,
here are the links:
Move Cursor
Here is my code:
- (void) shareToMailWithALAsset:(ALAsset *) asset {
if ([MFMailComposeViewController canSendMail]) {
NSString *imageName = asset.defaultRepresentation.filename;
MFMailComposeViewController *mailVC = [MFMailComposeViewController new];
mailVC.mailComposeDelegate = self;
[mailVC setMessageBody:"test"
isHTML:NO];
UIImage *image = [UIImage imageWithCGImage:asset.defaultRepresentation.fullScreenImage];
NSData *data = UIImageJPEGRepresentation(image, 1);
[mailVC addAttachmentData: data
mimeType:#"image/jpeg"
fileName:imageName];
[self presentViewController:mailVC
animated:YES
completion:nil];
}
else {
}
}
Any help will be appreciate. Thanks.
Related
I am using UIActivityViewController to share images.
As it share image on facebook or email. Then image gets rotate. Why it is so ?
My Code is as follows:
ShareArr contains image objects
ActivityViewCustomActivity *aVCA = [[ActivityViewCustomActivity alloc]init];
UIActivityViewController *controller = [[UIActivityViewController alloc] initWithActivityItems:shareArr applicationActivities:[NSArray arrayWithObject:aVCA]];
[controller setCompletionHandler:^(NSString *activityType, BOOL completed) { }];
[self presentViewController:controller animated:YES completion:nil];
Any idea ?
I know this was asked awhile ago but I ran into the same problem and here is my solution.
I found this site bug in UIActivityViewController
Here is the paragraph that I found useful from the site,
Notes: It seems when the system converts the UIImage into an NSData for the MFMailComposeViewController (and other UIActivities) it does NOT preserve the orientation information. This is why when an NSData is passed in, it is rotated correctly as the system doesn't have to convert it.
So here is part of the code I was using in my case (taking a photo),
NSData *imageData = [AVCaptureStillImageOutput jpegStillImageNSDataRepresentation:imageDataSampleBuffer];
UIImage *image = [[UIImage alloc] initWithData:imageData];
Then the facebook function from the UIActivityViewController was taking the UIImage and converting that back into NSData. So what I did was use the NSData *imageData and put that directly into my activityViewController.
Hope this helps someone.
I have an iOS app that should allow the user to select a pdf file and send it via there email account, I have the below code that presents the user with the email and shows the pdf attached, however with the email is send the pdf is not attached to the received email.
-(void)displayComposerSheet
{
MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
picker.mailComposeDelegate = self;
[picker setSubject:#"Public Holidays"];
NSString *plistFilePath = [[NSBundle mainBundle] pathForResource:currentCountry ofType:#"pdf"];
NSData *myData = [[NSFileManager defaultManager] contentsAtPath:plistFilePath];
[picker addAttachmentData:myData mimeType:#"application/pdf" fileName:currentCountry];
// Fill out the email body text
NSString *emailBody = #"Attached to this email is the PDF bought";
[picker setMessageBody:emailBody isHTML:NO];
[self presentModalViewController:picker animated:YES];
}
Code is correct. You should check the filename. Is it a valid string(filename). Also presentModalViewController is deprecated. You should use presentViewController:animated:completion. Check this on device, not on simulator.
I am trying to email a UIImage from my app. In my app I take a picture and then set a UIImageView to the picture that was just taken. Then I have a button which should email that picture as an attachment, like this:
- (IBAction)emailPhoto:(UIButton *)sender {
sendImage = imageView.image;
MFMailComposeViewController *composer = [[MFMailComposeViewController alloc] init];
[composer setMailComposeDelegate:self];
if([MFMailComposeViewController canSendMail]) {
[composer setToRecipients:[NSArray arrayWithObjects:#"JanJaap#Korteweg.nl",nil]];
[composer setSubject:#"A nice subject"];
[composer setMessageBody:#"Hi,\n\nI'm sending you this beautiful photograph." isHTML:NO];
[composer setModalTransitionStyle:UIModalTransitionStyleCrossDissolve];
NSData *data = UIImageJPEGRepresentation(sendImage,1);
[composer addAttachmentData:data mimeType:#"image/jpeg" fileName:#"Photograph.jpg"];
[self presentViewController:composer animated:YES completion:nil];
}
}
For some reason when I call this I get the composer window but it remains kind of greyed out and I can't edit anything (put in email address, type in body, etc). Also no attachment shows up. I deleted the image code and tried again and it all worked so the problem is somewhere in my handling of the image, but I am at a loss as to what that might be and I get no errors at all or warnings. I have tried a number of other strategies including bas64 encoding and saving the photo to the photo library and then retrieving it but they seem too complicated and result in never ending chains of warnings and errors. Any help appreciated. Thanks!
I have a camera application where the user can share the photos taken through email.
I am using MFMailComposerViewController to send mail. Here is the piece of code.
- (void) contactEmailRecepients:(NSArray *)emailIDs
subject:(NSString *)subject
attachment:(NSMutableDictionary *)attachmentDictionary
sender:(UIViewController *)sender
{
if ([MFMailComposeViewController canSendMail])
{
mailViewController = [[MFMailComposeViewController alloc] init];
mailViewController.mailComposeDelegate = self;
[mailViewController setToRecipients:emailIDs];
[mailViewController setSubject:subject];
NSData *attachmentData = [attachmentDictionary objectForKey:#"attachmentData"];
if (nil != attachmentData)
{
[mailViewController addAttachmentData:attachmentData
mimeType:[attachmentDictionary objectForKey:#"mimeType"]
fileName:[attachmentDictionary objectForKey:#"fileName"]];
}
[sender presentViewController:mailViewController
animated:YES
completion:^{}];
attachmentData = nil;
[attachmentDictionary removeAllObjects];
attachmentDictionary = nil;
}
else
{
// display error message
}
}
My problem is every time I send a mail through my application the VM(Virtual Memory) increases by 6/7 MB. But this does not happen if I comment out following part.
if (nil != attachmentData)
{
[mailViewController addAttachmentData:attachmentData
mimeType:[attachmentDictionary objectForKey:#"mimeType"]
fileName:[attachmentDictionary objectForKey:#"fileName"]];
}
The increased VM is due to CGRasterDataand the responsible library is CoreGraphicsand responsible caller is CGDataProvideCreateWithCopyOfDatawhen I check it through Xcode 5.0.2 instruments.So somewhere a copy is getting created which is not getting released later.I am suspecting the memory allocated to display the image in Email UIActionSheetis not getting released.
Any help is appreciated.
EDIT:
Adding the piece of code where attachmentData is getting initialized.
- (void)postPhotoFromPath:(NSString *)filePath
sender:(UIViewController *)sender
{
NSData *photoData = [NSData dataWithContentsOfFile:filePath];
if (nil == photoData)
{
//display error message
}
else
{
NSString *fileName = [[filePath componentsSeparatedByString:#"/"] lastObject];
[self contactEmailRecepients:nil
subject:nil
attachment:[NSDictionary dictionaryWithObjectsAndKeys:
photoData, #"attachmentData",
#"image/jpeg", #"mimeType",
fileName, #"fileName",
nil]
sender:sender];
}
}
Also I noticed carefully that VM increases exactly when i get the UIActionSheetregarding which image size to send(whether to send the original size or downscaled size). I am attaching the screenshot for the same here.
I am using the MessageUI framework to send and image via e-mail after taking the photo using UIImagePickerController. When I take the photo and then invoke the mail mail message interface I get the compose window. When testing on an iPod touch (iOS 4.3.5) and iPad (iOS 5.0.1) I see the image attachment in the body of the compose window. When testing on an iPhone (4S iOS 5.0.1) the image does not appear in the compose window, but rather I see a box the size of the image attachment with an embedded small blue box with a "?" in it.
In both cases when the mail message is sent the image appears in the message received in the Mail app - iOS devices and Mac.
What can I do to fix this?
UPDATE: I've worked around this by changing:
NSData *imageData = [NSData dataWithData:UIImagePNGRepresentation(imageToSend)]
to:
NSData *imageDataJPG = [NSData dataWithData:UIImageJPEGRepresentation(imageToSend, 1.0)];
I can't see in the UIKit docs that there is anything in UIImagePNGRepresentation that would not work on an iPhone ...
(Xcode 4.2.1, ARC, 5.0 SDK, Deploy target 4.3)
Here is the code for composing the message:
-(void)displayComposerSheet
{
MFMailComposeViewController *mailPicker = [[MFMailComposeViewController alloc] init];
mailPicker.mailComposeDelegate = self;
[mailPicker setSubject:#"Photo"];
NSData *imageData = [NSData dataWithData:UIImagePNGRepresentation(imageToSend)];
[mailPicker addAttachmentData:imageData mimeType:#"image/png" fileName:#"Photo"];
// Fill out the email body text.
NSString *line1 = [NSString stringWithFormat: #"I took this photo on my %#.\n", [[UIDevice currentDevice] model]];
NSString *body = [NSString stringWithFormat:#"%#", line1];
[mailPicker setMessageBody:body isHTML:NO];
// Present the mail composition interface.
[self presentModalViewController:mailPicker animated:YES];
}
The image size is restricted so if the image you are sending through is greater than a certain dimension you'll get the effect you describe above.
I had a look at my own code and saw I had
#define MAX_MAIL_DIM 1536
Which seems to be 1024 * 1.5. Sorry I can't remember how I arrived at that number but I suspect it was trial and error.
larik, your suggestion about using JPEG for the data type worked great. PNG files at this size are way too big anyway -- around 10MB. Here's the code with the JPEG NSData:
if ([MFMailComposeViewController canSendMail]) {
picker = [[MFMailComposeViewController alloc] init];
[picker setMailComposeDelegate:self];
[picker setSubject:#"My Picture"];
NSString *emailBody = #"";
[picker setMessageBody:emailBody isHTML:YES];
NSData *data = UIImageJPEGRepresentation(tempImage, 0);
[picker addAttachmentData:data mimeType:#"image/jpg" fileName:#"CameraImage"];
}