Is it possible to share an image via UIActivityVie

2019-06-23 22:11发布

I have an app which saves images to a custom album within the camera roll via

    [library writeImageToSavedPhotosAlbum:[newTestImage CGImage] metadata:metadata
      completionBlock:^(NSURL *assetURL, NSError *error) {
        //error
      }
    ];

This works fine, however, I would then like to allow the user to share these images from within the app, I was doing it via

    ALAsset *assetToShare = self.images[indexPath.row];
        NSString *stringToShare = @"…..";
        NSArray *dataToShare = @[assetToShare, stringToShare];

        UIActivityViewController *activityVC = [[UIActivityViewController alloc]
              initWithActivityItems:dataToShare applicationActivities:nil];

        [self presentViewController:activityVC animated:YES completion: ^{
            //Some Expression  
        }];}

However in doing so the image is stripped of all exif data, is there a way I can implement the same functionality but retain the metadata? Thanks very much for any assistance.

Edit: Code used to enter ALAssets

    if ([[group valueForProperty:ALAssetsGroupPropertyName] isEqualToString:@"my pics"]) {
                           [self.assetGroups addObject:group];
                           _displayArray = [self.assetGroups objectAtIndex:0]; ...}];

Then:

   [_displayArray enumerateAssetsUsingBlock:^(ALAsset *result, NSUInteger index, BOOL *stop) {
    if (result) {
        [self.images addObject:result]; }];

1条回答
倾城 Initia
2楼-- · 2019-06-23 22:51

Have you tried something like this? Just passing the actual image.

ALAsset *assetToShare = self.images[indexPath.row];

ALAssetRepresentation *rep = [assetToShare defaultRepresentation];

UIImage *imageToShare = [UIImage imageWithCGImage:[rep fullResolutionImage]];

NSString *stringToShare = @"…..";
NSArray *dataToShare = @[imageToShare, stringToShare];

UIActivityViewController *activityVC = [[UIActivityViewController alloc]
initWithActivityItems:dataToShare applicationActivities:nil];

[self presentViewController:activityVC animated:YES completion: ^{
//Some Expression
}];}
查看更多
登录 后发表回答