【问题标题】:Sharing video with airdrop通过空投分享视频
【发布时间】:2015-09-02 05:44:58
【问题描述】:

我在使用空投分享视频时遇到了一些问题。所以,我像这样使用AssetLibrary:

else if (conformsToVideo) {

        UIAlertView *alert = [[UIAlertView alloc]  initWithTitle:@"Asset Loaded" message:@"Video One Loaded"
        delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
        [alert show];

        self.mediaAsset = [AVAsset assetWithURL:[info objectForKey:UIImagePickerControllerMediaURL]];

        UIActivityViewController * controller = [[UIActivityViewController alloc] initWithActivityItems:@[self.mediaAsset] applicationActivities:nil];
        [self presentViewController:controller animated:YES completion:nil];
}

也许这不是这样做的方法,我不知道,也没有找到任何关于它的教程,所以如果你有,我很乐意接受。

现在我的问题是,当我选择一个视频时,一切正常,直到 UIActivityViewController 弹出,我没有任何错误但我不能使用空投 (nor any other service BTW) 我唯一能做的就是按UIAVController的Cancel button。

我正在使用iOS 8.3。

感谢您的帮助

【问题讨论】:

    标签: ios video avasset airdrop


    【解决方案1】:

    好的,最终我找到了答案,也许不是最好的,但我把它放在那里以防它对某人有帮助,因为我在与空投共享视频方面没有找到太多:

    NSURL * path = [info objectForKey:UIImagePickerControllerReferenceURL];
    BOOL conformsToVideo = (UTTypeConformsTo((__bridge_retained CFStringRef) mediaType, kUTTypeAudiovisualContent));
    
    if (conformsToVideo) {
    
                [self.library assetForURL:path
                              resultBlock:^(ALAsset *asset) {
                                  ALAssetRepresentation* assetRepresentation = [asset defaultRepresentation];
                                  NSString* outputDirectory = [NSString stringWithFormat:@"%@", NSTemporaryDirectory()];
                                  NSString* pathToCopy = [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];
                                  NSURL * url = nil;
                                  if ([data writeToFile:pathToCopy atomically:YES])
                                  {
                                      NSLog(@"Ok");
                                      url = [NSURL fileURLWithPath:pathToCopy];
                                      UIActivityViewController * controller = [[UIActivityViewController alloc] initWithActivityItems:@[url] applicationActivities:nil];
                                      [self presentViewController:controller animated:YES completion:nil];
                                  }
                              } failureBlock:^(NSError *error) {
                                  NSLog(@"Failure to use the ALAsset");
    
                              }
                 ];
            }
    

    我使用这个问题找到了解决方案:Share a video from asset library with AirDrop fails 我只是将前面的步骤添加到那里给出的代码中,希望它有用。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-02-05
      • 2015-08-17
      • 2017-09-28
      • 2013-02-01
      • 1970-01-01
      • 2017-08-13
      • 2014-04-30
      相关资源
      最近更新 更多