2015-09-02 77 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 我只是將前面的步驟添加到給定的代碼,希望它可以是有用的。