如何使用 Facebook iOS SDK 4.0 FBSDKShareDialog 共享 NSData 或 phasset 视频 [英] How to share NSData or phasset video using Facebook iOS SDK 4.0 FBSDKShareDialog

查看:38
本文介绍了如何使用 Facebook iOS SDK 4.0 FBSDKShareDialog 共享 NSData 或 phasset 视频的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我注意到你可以简单地将 NSData 视频分享到 Facebook Messenger:

I noticed you can share NSData video to facebook messenger simply:

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

但我在分享到 Facebook 提要时遇到了同样的困难使用本地视频文件或相位集.

But I’m having difficulties doing the same when sharing to facebook feed using local video file or phasset.

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 视频实现类似的出色应用切换行为?

How would I go about having similar nice app-switching behavior using phasset video?

谢谢!

推荐答案

在新的 Facebook SDK 4.0 中,视频必须作为资产 URL 传递.您必须将本地视频路径复制到资产库,并使用生成的 URL 在 Facebook 上分享.

With the new Facebook SDK 4.0, videos must be passed as assets URL. You have to copy your local video path to Assets Library and use that generated URL to share on Facebook.

第一步:

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

如果您有任何其他疑问,请告诉我.

If you have any other query please let me know.

谢谢!

这篇关于如何使用 Facebook iOS SDK 4.0 FBSDKShareDialog 共享 NSData 或 phasset 视频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆