You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何使用FBSDK分享视频时唤起Facebook原生分享对话框?

Facebook Native Video Share Not Working (Image Share Works Perfectly)

Hey folks, I've been stuck on this issue for a bit and could use some help. My app can seamlessly jump to the Facebook native app to share images with user confirmation, but when I try the same flow for videos, nothing happens—no dialog, no app switch, no post. Let me walk through what I've tried so far:

What's Working (Image Share Flow)

This code works exactly as expected: it opens the Facebook app, lets me preview the image, and confirm the post before publishing:

let sharePhoto = FBSDKSharePhoto()
sharePhoto.image = photo
let content = FBSDKSharePhotoContent()
content.photos = [sharePhoto]
let shareDialog: FBSDKShareDialog = FBSDKShareDialog()
shareDialog.shareContent = content
shareDialog.mode = .native
shareDialog.show()

What's Failing (Video Share Attempts)

I’ve tried multiple approaches for video sharing, none of which trigger the native Facebook app flow I want:

  1. Basic Native Video Dialog: No feedback at all—no popups, no app switch, video never posts:
let shareVdo: FBSDKShareVideo = FBSDKShareVideo()
shareVdo.videoURL = self.fileURL
let vdoContent = FBSDKShareVideoContent()
vdoContent.video = shareVdo
let shareDialog: FBSDKShareDialog = FBSDKShareDialog()
shareDialog.shareContent = vdoContent
shareDialog.mode = .native
shareDialog.show()
  1. FBSDKShareAPI for Video: This does share the video, but it’s silent—no user interaction, no app switch, and the post goes live immediately (not the user-confirm flow I need):
let shareVdo: FBSDKShareVideo = FBSDKShareVideo()
shareVdo.videoURL = self.fileURL
let vdoContent = FBSDKShareVideoContent()
vdoContent.video = shareVdo
FBSDKShareAPI.share(with: vdoContent, delegate:self)
  1. Converting to Asset URL: I tried converting the local file URL to an asset URL using AVAsset, but the native dialog still won’t trigger:
let shareVdo: FBSDKShareVideo = FBSDKShareVideo()
let asset = AVAsset(url: self.fileURL)
let assetURL = self.getAssetUrl(asset:asset)
shareVdo.videoURL = assetURL
let vdoContent = FBSDKShareVideoContent()
vdoContent.video = shareVdo
//FBSDKShareAPI.share(with: vdoContent, delegate:self)
let shareDialog: FBSDKShareDialog = FBSDKShareDialog()
shareDialog.shareContent = vdoContent
shareDialog.mode = .native
shareDialog.show()
  1. Adding Preview Thumbnail: Even initializing FBSDKShareVideo with a valid preview (my video is only 4.4MB, well under the 12MB limit) didn’t help. My hunch is the SDK requires videos to be sourced from the device’s photo library?

My Goal

I need to replicate the image share flow exactly: jump to the Facebook native app, let the user review and confirm the video post, then publish it.


Potential Fixes & Solution

After digging into Facebook’s SDK docs and testing, here’s what worked for me:

1. Save the Video to the Photo Library First

Facebook’s native share dialog can’t access local file URLs directly for videos—it requires the video to be in the device’s photo library (accessible via ph:// or assets-library:// URLs). Here’s how to save your video to the library and share it via the native flow:

import Photos

// Step 1: Save video to photo library and get its asset URL
func saveVideoToLibraryAndShare(_ videoFileURL: URL) {
    PHPhotoLibrary.requestAuthorization { authStatus in
        guard authStatus == .authorized else {
            // Handle permission denied (show alert to user)
            return
        }
        
        PHPhotoLibrary.shared().performChanges({
            PHAssetChangeRequest.creationRequestForAssetFromVideo(atFileURL: videoFileURL)
        }) { success, error in
            guard success, error == nil else {
                print("Failed to save video: \(error?.localizedDescription ?? "Unknown error")")
                return
            }
            
            // Fetch the newly saved video asset
            let fetchOptions = PHFetchOptions()
            fetchOptions.sortDescriptors = [NSSortDescriptor(key: "creationDate", ascending: false)]
            let videoAssets = PHAsset.fetchAssets(with: .video, options: fetchOptions)
            
            if let latestVideo = videoAssets.firstObject, let assetURL = latestVideo.url {
                DispatchQueue.main.async {
                    self.shareVideoViaFacebookNative(assetURL: assetURL)
                }
            }
        }
    }
}

// Step 2: Share the library video via Facebook native dialog
func shareVideoViaFacebookNative(assetURL: URL) {
    let shareVideo = FBSDKShareVideo()
    shareVideo.videoURL = assetURL
    
    let content = FBSDKShareVideoContent()
    content.video = shareVideo
    
    let shareDialog = FBSDKShareDialog()
    shareDialog.shareContent = content
    shareDialog.mode = .native
    // Add fallback to web if Facebook app isn't installed
    shareDialog.fallbackMode = .web
    
    if shareDialog.canShow() {
        shareDialog.show()
    } else {
        print("Facebook app isn't installed or can't handle this share")
        // Fallback to web share or show error to user
    }
}

2. Double-Check SDK Setup & Permissions

  • Make sure you’re using the latest version of the Facebook SDK (update via CocoaPods/Swift Package Manager).
  • Verify your Info.plist has all required Facebook entries:
    • FacebookAppID and FacebookDisplayName
    • LSApplicationQueriesSchemes includes fb and fbapi
    • Correct URL scheme (e.g., fbYOUR_APP_ID) for Facebook interactions

3. Confirm Video Meets Specs

  • File size: Under 12MB (your 4.4MB is fine)
  • Format: MP4 or MOV
  • Duration: Under 120 minutes

Why This Works

The Facebook native app needs access to the video via the system’s photo library to enable the interactive preview/confirm flow. Local files aren’t accessible across apps, so saving to the library makes the video available for Facebook to pull into its native share interface.

内容的提问来源于stack exchange,提问作者Chewie The Chorkie

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.27 07:28:03