簡體   English   中英

如何使用Facebook iOS SDK 4.0 FBSDKShareDialog分享NSData或phasset視頻

[英]How to share NSData or phasset video using Facebook iOS SDK 4.0 FBSDKShareDialog

我注意到你可以簡單地將NSData視頻分享給facebook messenger:

NSData *videoData = [NSData dataWithContentsOfURL:localVideoUrl];
[FBSDKMessengerSharer shareVideo:videoData withOptions:options];

但是當我使用本地視頻文件或phasset分享到Facebook Feed時,我遇到了同樣的困難。

FBSDKShareVideo *video = [FBSDKShareVideo videoWithVideoURL:localVideoUrl];
FBSDKShareVideoContent *content = [[FBSDKShareVideoContent alloc] init];
[content setVideo: video];
[FBSDKShareDialog showFromViewController:nil withContent:content delegate:self];

com.facebook.sdk:FBSDKErrorDeveloperMessageKey =原生對話框只允許使用資產文件URL

我如何使用phasset視頻進行類似的不錯的應用切換行為?

謝謝!

使用新的Facebook SDK 4.0,視頻必須作為資產URL傳遞。 您必須將本地視頻路徑復制到資產庫,並使用生成的URL在Facebook上共享。

步驟1:

NSURL *videoURL=[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"IMG_1007" ofType:@"mp4"]];
[self saveToCameraRoll:videoURL];

第2步:

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

    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:srcURL])
    {
        [library writeVideoAtPathToSavedPhotosAlbum:srcURL
                                    completionBlock:videoWriteCompletionBlock];
    }
}

第3步:

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];

如果您有任何其他疑問,請告訴我。

謝謝!

請檢查:1)視頻的大小必須小於12MB。 2)分享的人應安裝Facebook for iOS客戶端,版本26.0或更高版本。

你應該使用以下行:

NSURL *movieUrl = [info objectForKey:UIImagePickerControllerReferenceURL];

代替

NSURL *movieUrl = [info objectForKey:UIImagePickerControllerMediaURL];

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM