Share a video from asset library with AirDrop fails

864 views Asked by At

Using AirDrop, I would like to share a video from the asset library.

In regards to AirDrop, the documentation says:

When using this service, you can provide NSString, NSAttributedString, UIImage, ALAsset, and NSURL objects as data for the activity items. You may also specify NSURL objects whose contents use the assets-library scheme. You may also provide NSArray or NSDictionary objects that contain the listed data types.

What I'm seeing thought is that if the data of the activity item is an NSURL with assets-library scheme, the transfer fails with the following error:

Sender kSFOperationEventErrorOccured { Error = "Error Domain=SFOperation Code=-6 \"The transfer failed because you don\U2019t have permission to read \U201cIMG_0119.MP4\U201d.\" UserInfo=0x155f5db0 {NSLocalizedDescription=The transfer failed because you don\U2019t have permission to read \U201cIMG_0119.MP4\U201d.}"; FileIcon = ""; Files = ( ); SessionID = 9165CCC70A39; }

The only way I'm able to successfully share a video that is in the asset library via AirDrop is if I copy the file to a temporary location and then set the data of the activity item to the new NSURL. Basically something like this:

- (id)activityViewController:(UIActivityViewController *)activityViewController   itemForActivityType:(NSString *)activityType
  {
      ALAssetRepresentation* assetRepresentation = [self.asset defaultRepresentation];

      NSString* outputDirectory = [NSString stringWithFormat:@"%@", NSTemporaryDirectory()];
      NSString* path = [outputDirectory stringByAppendingPathComponent:[NSString stringWithFormat:@"%@", assetRepresentation.filename]];

      NSUInteger size = (NSUInteger)assetRepresentation.size;
      NSMutableData* data = [NSMutableData dataWithLength:size];

      NSUInteger bytesRead = [assetRepresentation getBytes:data.mutableBytes fromOffset:0 length:size error:nil];
      if ([data writeToFile:path atomically:YES])
      {
          self.url = [NSURL fileURLWithPath:path];
      }
      return url;
}

Does anyone have managed to share a video from the asset library without copying the file to a temporary location? Am I missing something or is this a bug in the SDK?

0

There are 0 answers