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

查看:526
本文介绍了如何使用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 feed
时,我也遇到困难文件或phasset。

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.

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

如果您有任何其他查询请通知我。

If you have any other query please let me know.

谢谢!

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

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