使用fb sdk在ios上共享视频
我对iOS编程非常陌生,因此,这个问题可能看起来很愚蠢,但我真的不知道哪里出了问题 所以,我一直在关注iOS上的分享,我成功地分享了链接和照片。但我不知道为什么我不能分享视频。我没有使用使用fb sdk在ios上共享视频,ios,objective-c,share,fbsdk,Ios,Objective C,Share,Fbsdk,我对iOS编程非常陌生,因此,这个问题可能看起来很愚蠢,但我真的不知道哪里出了问题 所以,我一直在关注iOS上的分享,我成功地分享了链接和照片。但我不知道为什么我不能分享视频。我没有使用UIImagePickerControllerReferenceURL,而是使用[[NSBundle mainBundle]URLForResource:@“xyz”和扩展名:@“mp4”]作为视频URL 这就是为什么共享按钮不起作用的原因吗 我的目标是让用户直接分享应用程序中的内容。因此,我不希望他们使用UII
UIImagePickerControllerReferenceURL
,而是使用[[NSBundle mainBundle]URLForResource:@“xyz”和扩展名:@“mp4”]
作为视频URL这就是为什么共享按钮不起作用的原因吗 我的目标是让用户直接分享应用程序中的内容。因此,我不希望他们使用
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所需的资产库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];
}
}
然后
换成这个
NSURL* videoURL = [[NSBundle mainBundle] URLForResource:@"xyz" ofType:@"mp4"];
[self saveToPhotoAlbum:videoURL];
之后,将此视频保存到照片库,作为Facebook所需的资产库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];
}
}
然后
您可以将代码粘贴到这里吗。@RohitKP,我已经对问题进行了编辑以包含代码。您可以将代码粘贴到这里吗。@RohitKP,我已经对问题进行了编辑以包含代码。感谢您的代码,但使用alasset我们会收到此警告,-->AlassetLibrary“已弃用:首先在iOS 9.0中弃用-请改用照片框架中的PHPhotoLibrary。您可以更新此代码吗谢谢您的代码,但使用alasset我们会收到此警告,-->AlassetLibrary“已弃用:首先在iOS 9.0中弃用-请改用照片框架中的PHPhotoLibrary。你能更新这个代码吗