2015-09-02 42 views
1

我在空投分享视频时遇到了一些麻烦。所以,我现在用的是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),我唯一可以做的就是按Cancel buttonUIAVController。我正在使用iOS 8.3

感谢您的帮助

回答

0

好吧,最终我找到了答案,也许不是最好的,但我把它放在那里的情况下,它可以帮助别人因为我没有找到太多与空投分享视频:

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 我只是将前面的步骤添加到给定的代码,希望它可以是有用的。