Share a video from asset library with AirDrop fails

允我心安 提交于 2019-12-10 22:29:37

问题


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?

来源:https://stackoverflow.com/questions/23798846/share-a-video-from-asset-library-with-airdrop-fails

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!