Search code examples
iosswiftfacebookfacebook-share

FBSDKShareDialog not appearing in case of video share


I am working on a project where I need to share an image and a video together on Facebook, but facing undefined behaviour.

Issue: When I am trying to share a video using FBSDKShareMediaContent class (using below code), the FBSDKShareDialog is not appearing, but it appears when I share only an image.

My code:

let photo: FBSDKSharePhoto = FBSDKSharePhoto.init(image: imageToShare, userGenerated: true)

let vid: FBSDKShareVideo = FBSDKShareVideo.init(videoURL: URL(string:vidUrl!.path))

 //  FBSDKShareDialog not appearing in this case 
let shareContent: FBSDKShareMediaContent = FBSDKShareMediaContent()
shareContent.media = [photo, vid]

/*
// FBSDKShareDialog appearing 
let shareContent: FBSDKShareMediaContent = FBSDKShareMediaContent()
shareContent.media = [photo]  */


FBSDKShareDialog.show(from: self.getCurrentViewController(), with: shareContent, delegate: nil)

Video URL: file:///var/mobile/Containers/Data/Application/2E0E48B7-30E5-4567-8C0B-ACAC100AE389/Documents/AppName/1499773278.555753.mp4

Please help.


Solution

  • The solution i found is, the url path i was assigning is wrong as per the Facebook guidelines of sharing video.

    The video URL videoURL must be an asset URL. You can get a video asset URL e.g. from UIImagePickerController.

    See video sharing section inside the link.

    UPDATE:

    Final Solution to share image, video together using picker or document directory path whichever, this works.

    let shareText = "Upload video, image and text."
    let vc = UIActivityViewController(activityItems: [shareText, vidUrl, imageToShare], applicationActivities: [])
    present(vc, animated: true)