How to share NSData or phasset files using Facebook iOS SDK 4.0 FBSDKShareDialog

I noticed that you can share NSData video for facebook messenger:

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

But I have difficulties with the same thing when you share facebook files using a local video file or a fasset.

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

com.facebook.sdk: FBSDKErrorDeveloperMessageKey = Only resource file URLs allowed for native dialog

How do I like this behavior when using the app using the phasset video file?

Thanks!

+5
source share
2 answers

In the new Facebook SDK 4.0, videos should be streamed as an asset URL. You must copy your local video path to the asset library and use this generated URL to post to Facebook.

Step 1:

 NSURL *videoURL=[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"IMG_1007" ofType:@"mp4"]]; [self saveToCameraRoll:videoURL]; 

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

Step 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 questions, please let me know.

Thanks!

+12
source

Please check: 1) The video must be less than 12 MB. 2) People who share must have Facebook installed for the iOS client, version 26.0 or higher.

You should use the following line:

 NSURL *movieUrl = [info objectForKey:UIImagePickerControllerReferenceURL]; 

instead

 NSURL *movieUrl = [info objectForKey:UIImagePickerControllerMediaURL]; 
0
source

All Articles