gpt4 book ai didi

ios - 如何使用 Facebook iOS SDK 4.0 FBSDKShareDialog 分享 NSData 或 phasset 视频

转载 作者:可可西里 更新时间:2023-11-01 04:18:10 24 4
gpt4 key购买 nike

我注意到您可以简单地将 NSData 视频分享到 facebook messenger:

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

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

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

com.facebook.sdk:FBSDKErrorDeveloperMessageKey= native 对话框只允许 Assets 文件 URL

我如何使用 phasset 视频实现类似的良好应用切换行为?

谢谢!

最佳答案

使用新的 Facebook SDK 4.0,视频必须作为 Assets URL 传递。您必须将本地视频路径复制到 Assets Library 并使用生成的 URL 在 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];

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

谢谢!

关于ios - 如何使用 Facebook iOS SDK 4.0 FBSDKShareDialog 分享 NSData 或 phasset 视频,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29386478/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com