Share Video to Facebook

  • You can create a share dialog with sharing content type VideoShareContent object that is supported in the Facebook SDK for Swift.
  • In order to share video the user must have the native Facebook for iOS app installed.
  • Photos & Videos must be less than 12MB in size.
The Facebook SDK for Swift mainly supports sharing of videos from Photo Library and supports AVAsset URL format which is currently deprecated. So here we need to convert PHAsset URL to AVAsset URL .

 AVAsset URL: "assets-library://asset/asset.MOV?id=\(videoId[0])&ext=MOV" 


func fbUpload(path:URL){
        let video = Video(url: path)
        var content = VideoShareContent(video: video)
        content.video = video
        showShareDialog(content)
    }
    
  func showShareDialog<C: ContentProtocol>(_ content: C, mode: ShareDialogMode = .automatic) {
        let dialog = ShareDialog(content: content)
        dialog.presentingViewController = self.aViewController
        dialog.mode = mode      
        do{
            try dialog.show()
        }
        catch (let error){
            print(error)
        }
 }

Comments

Popular Posts