2016-06-30 7 views
0

私はiOSでプログラミングするのがとても新しいので、質問はむしろばかげているかもしれませんが、何が間違っているのか本当に分かりません。iosでfb sdkを使ってビデオを共有

私はhttps://developers.facebook.com/docs/sharing/iosでiOSで共有していたので、リンクや写真を共有できました。しかし、なぜビデオを共有できないのか分かりません。私はUIImagePickerControllerReferenceURLを使用していませんが、代わりにvideoURLには[[NSBundle mainBundle] URLForResource:@"xyz" withExtension:@"mp4"]を使用しています。
これが共有ボタンが機能しない理由ですか?

私の目標は、ユーザーが直接アプリケーションからコンテンツを共有できるようにすることです。だから私は彼らにUIImagePickerControllerReferenceURLを使わせたくない。ここ
はコードです:

NSURL* videoURL = [[NSBundle mainBundle] URLForResource:@"xyz" withExtension:@"mp4"]; 
FBSDKShareVideo *video = [[FBSDKShareVideo alloc] init]; 
video.videoURL = videoURL; 
FBSDKShareVideoContent *content = [[FBSDKShareVideoContent alloc] init]; 
content.video = video; 

FBSDKShareButton *button = [[FBSDKShareButton alloc] init]; 
button.center = self.view.center; 
button.shareContent = content; 
[self.view addSubview:button]; 

とファイルxyz.mp4は、メディアフォルダです。

+0

あなたはここにコードを貼り付けることができます。 –

+0

@RohitKP、私はコードを組み込むために質問を編集しました。 – user5497505

答えて

2
NSURL* videoURL = [[NSBundle mainBundle] URLForResource:@"xyz" withExtension:@"mp4"]; 

Facebookは、資産ライブラリのURLを必要に応じてそれがフォトライブラリにこのビデオを保存した後、この

NSURL* videoURL = [[NSBundle mainBundle] URLForResource:@"xyz" ofType:@"mp4"]; 

[self saveToPhotoAlbum:videoURL]; 

と交換してください。

-(void)saveToPhotoAlbum:(NSURL*)url 
{ 
NSLog(@"srcURL: %@", url); 

    ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init]; 
    ALAssetsLibraryWriteVideoCompletionBlock videoWriteCompletionBlock = 
    ^(NSURL *newURL, NSError *error) { 
     if (error) { 
      NSLog(@"Error writing image with metadata to Photo Library: %@", error); 
     } else { 
      NSLog(@"Wrote image with metadata to Photo Library %@", newURL.absoluteString); 
      url_new = newURL; 
     } 
    }; 

    if ([library videoAtPathIsCompatibleWithSavedPhotosAlbum:url]) 
    { 
     [library writeVideoAtPathToSavedPhotosAlbum:url 
            completionBlock:videoWriteCompletionBlock]; 
    } 
} 

その後、

FBSDKShareDialog *shareDialog = [[FBSDKShareDialog alloc] init];  
NSURL *videoURL = url_new; 
FBSDKShareVideo *video = [[FBSDKShareVideo alloc] init]; 
video.videoURL = videoURL; 
FBSDKShareVideoContent *content = [[FBSDKShareVideoContent alloc] init]; 
content.video = video; 
shareDialog.shareContent = content; 
shareDialog.delegate = self; 
[shareDialog show]; 
関連する問題