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?
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:^{}];
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];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With