gpt4 book ai didi

ios - 使用 fb sdk 在 ios 上共享视频

转载 作者:行者123 更新时间:2023-11-28 21:25:49 26 4
gpt4 key购买 nike

我是 iOS 编程的新手,因此,这个问题可能看起来很愚蠢,但我真的不知道哪里出了问题。

所以,我在 https://developers.facebook.com/docs/sharing/ios 上关注 iOS 中的分享。我成功地分享了链接和照片。但是我不知道为什么我不能分享视频。我没有使用 UIImagePickerControllerReferenceURL,而是使用 [[NSBundle mainBundle] URLForResource:@"xyz"withExtension:@"mp4"] 作为 videoURL.
这就是分享按钮不起作用的原因吗?

我的目标是让用户直接从应用分享内容。所以我不希望他们使用 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 位于媒体文件夹中。

最佳答案

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

替换成这个

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

[self saveToPhotoAlbum:videoURL];

之后将此视频保存到照片库,作为 Facebook 所需的 Assets 库 url。

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

关于ios - 使用 fb sdk 在 ios 上共享视频,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38113833/

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