Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set email attachment file name using UIActivityViewController email sharing

I am trying to share camera roll image using UIAcitivityViewController email sharing.

Following are my code.

 ALAssetRepresentation *rep = [asset defaultRepresentation];
    CGImageRef iref = [rep fullScreenImage];
    UIImage *largeimage = [UIImage imageWithCGImage:iref scale:[rep scale] orientation:UIImageOrientationUp];
    NSData *imageData = UIImageJPEGRepresentation(largeimage, 1.0);
    NSArray *activityItems;

    if (largeimage != nil) {
        activityItems = @[imageData];
    }

    UIActivityViewController *activityController = [[UIActivityViewController alloc] initWithActivityItems:activityItems applicationActivities:nil];
    [self presentViewController:activityController animated:YES completion:nil];

I don't know how can I set attachment image file name. Any advice?

like image 484
ttotto Avatar asked Jan 15 '13 02:01

ttotto


2 Answers

Try saving image locally, then send the file url instead, it will show your image name surely.

ALAssetRepresentation *rep = [asset defaultRepresentation];
CGImageRef iref = [rep fullScreenImage];
UIImage *largeimage = [UIImage imageWithCGImage:iref scale:[rep scale] orientation:UIImageOrientationUp];
NSData *imageData = UIImageJPEGRepresentation(largeimage, 1.0);
// Store imageData locally
NSString* documentsPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
NSString* filePath = [documentsPath stringByAppendingPathComponent:"@abc.jpg"];
[imageData writeToFile:filePath atomically:YES];
NSURL *fileUrl = [NSURL fileURLWithPath:filePath];

UIActivityViewController* activityViewController = [[UIActivityViewController alloc] initWithActivityItems:@[fileUrl]
                                          applicationActivities:nil];
[self.navigationController presentViewController:activityViewController animated:YES completion:^{}];
like image 137
thanhbinh84 Avatar answered Nov 15 '22 17:11

thanhbinh84


try this...

NSString *text = @"write text here";
UIImage *image = [UIImage imageNamed:@"your image name"];
NSArray *activityItems = [NSArray arrayWithObjects:text,image , nil];
UIActivityViewController *activityController = [[UIActivityViewController alloc] initWithActivityItems: activityItems applicationActivities:nil];
[self presentViewController:activityController animated:YES completion:nil];
like image 1
Swift-Master Avatar answered Nov 15 '22 17:11

Swift-Master