Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIActivityViewController sharing image via email has no extension

The image attached is just "Attachment-1", no extension. How do I specify one ?

    NSData *compressedImage = UIImageJPEGRepresentation(self.resultImage, 0.8 );

    UIActivityViewController *activityViewController = [[UIActivityViewController alloc] initWithActivityItems:@[ @"Check this out!", compressedImage ] applicationActivities:nil];

    [self.navigationController presentViewController:activityViewController animated:YES completion:nil];
like image 586
Thomas Joulin Avatar asked Apr 05 '13 04:04

Thomas Joulin


1 Answers

According to this answer you should be able to use this workaround to specify a filename

NSData *compressedImage = UIImageJPEGRepresentation(self.resultImage, 0.8 );
NSString *docsPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
NSString *imagePath = [docsPath stringByAppendingPathComponent:@"image.jpg"];
NSURL *imageUrl     = [NSURL fileURLWithPath:imagePath];

[compressedImage writeToURL:imageUrl atomically:YES]; // save the file
UIActivityViewController *activityViewController = [[UIActivityViewController alloc] initWithActivityItems:@[ @"Check this out!", imageUrl ] applicationActivities:nil];

The obvious drawback of this approach is that you will have to save the image on disk.

like image 77
Gabriele Petronella Avatar answered Nov 04 '22 07:11

Gabriele Petronella