Reputation: 9
There are a LOT of tutorials and info about how to send attachment with your iphone / ipad app, but with pre-defined images or other file-type. But how do i send an mail with a current file from my iphone/ipad. More specific, an image or image from camera?
Cheers and thank you
Upvotes: 0
Views: 437
Reputation: 19418
If you are using UIImagePickerController
to capture image than when you capture image :
#import <MobileCoreServices/UTCoreTypes.h> // framework MobileCoreServices.framework
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
NSString *mediaType = [info objectForKey:UIImagePickerControllerMediaType];
if ([mediaType isEqualToString:(NSString *)kUTTypeImage])
{
UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage];
[self sendMailWithImage:image];
}
[picker dismissModalViewControllerAnimated:NO];
}
- (void)sendMailWithImage:(UIImage *)image
{
MFMailComposeViewController * mailComposer = [[MFMailComposeViewController alloc]init];
mailComposer.mailComposeDelegate = self;
// make sure you can make NSData from the object
[mailComposer addAttachmentData:UIImageJPEGRepresentation(image, 1.0) mimeType:@"image/jpg" fileName:@"what ever you want to call the file"];
[self presentViewController:mailComposer animated:YES completion:nil];
}
Upvotes: 1
Reputation: 15266
MFMailComposeViewController * mailComposer = [[MFMailComposeViewController alloc]init];
mailComposer.mailComposeDelegate = self;
UIImage *myImage = // some code to get your image or what ever file you want
// make sure you can make NSData from the object
[mailComposer addAttachmentData:UIImageJPEGRepresentation(imageToShare, 1.0) mimeType:@"image/jpg" fileName:@"what ever you want to call the file"];
[self presentViewController:mailComposer animated:YES completion:nil];
Upvotes: 0