3

Currently I have a tableview listed with jpg images populated from a server. When i select one of the images the UIActivityController is displayed however there is no option for save to camera roll. The only options are the share to facebook, twitter, mail etc.

I would like it so I can have the option to save the image to the camera roll and also another option to click "view" and it will display it in a new detailed view. I mainly want to be able to save to the camera roll first then work on showing the detailed view.

This is the code i have so far.

    - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath*)indexPath
{
static NSString *CellIdentifier = @"Cell";

UITableViewCell *cell = [tableView
                         dequeueReusableCellWithIdentifier:CellIdentifier];


NSString *path = [NSString stringWithFormat:@"http://10.1.4.2:8080/DCIM/DCIM/VIDEOS/%@", [movieArray objectAtIndex:indexPath.row]];
NSString *ext = [[path pathExtension] lowercaseString];

if([ext isEqualToString:@"jpg"]) {


    UIActivityViewController *objVC = [[UIActivityViewController alloc]initWithActivityItems:[NSArray arrayWithObjects:[NSURL URLWithString:path], nil] applicationActivities:nil];


    [self presentViewController:objVC animated:YES completion:nil];

}
teejay
  • 53
  • 1
  • 4
  • FYI. In my case (XCode 13, iOS 15), to show "Save Image" option in activity view, first you need to add "Privacy - Photo Library Additions Usage Description” in info.plist. – Hong Feb 18 '22 at 06:05

2 Answers2

2

If you want the image to be saved, you need to pass in a UIImage object, not an NSURL object. See sample code in this Stack Overflow answer.

Community
  • 1
  • 1
Aaron Brager
  • 65,323
  • 19
  • 161
  • 287
2

I figured out that to have an option to save the images to camera roll via UIActivityViewController - it's required to add

<key>NSPhotoLibraryAddUsageDescription</key>
<string>to let you export images to photo library</string>

to your Info.plist file.

Naloiko Eugene
  • 2,453
  • 1
  • 28
  • 18