Search code examples
iphoneuiactivityindicatorviewemail-attachments

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?


Solution

  • 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];