简体   繁体   中英

iOS Facebook share video Swift

I am looking for a way to share a video of my application on Facebook. I installed the SDK to facebook and followed the instructions but I do not understand why I can not share my video.

let fbVideo:FBSDKShareVideo = FBSDKShareVideo()
fbVideo.videoURL = url
let content: FBSDKShareVideoContent = FBSDKShareVideoContent()
content.video = fbVideo
FBSDKShareDialog.showFromViewController(self, withContent: content, delegate: self)

I have one error with the parameter delegate :

Cannot convert value of type 'ShareViewController' to expected argument type 'FBSDKSharingDelegate!'

Note that I am in my class ShareViewController.

There are no other means to share a video on facebook ? thank you

The method showFromViewController:withContent:delegate: expects the delegate argument to be of type FBSDKSharingDelegate . You are providing a value of type ShareViewController not FBSDKSharingDelegate which means said view controller does not conform to that type. You would need to make your view controller to conform to type FBSDKSharingDelegate . As an example:

class ShareViewController: UIViewController, FBSDKSharingDelegate {
    // code
}

Or pass in another object that conforms to type FBSDKSharingDelegate .

You have to implement FBSDKSharingDelegate protocol and it's methods.

    class ViewController: UIViewController ,FBSDKSharingDelegate{

    //add following methods to the class:
func sharer(_ sharer: FBSDKSharing!, didCompleteWithResults results: [AnyHashable : Any]!) {
            print("Completed");
        }


        func sharer(_ sharer: FBSDKSharing!, didFailWithError error: Error!) {
            print("Failed with error : \(error.localizedDescription)");
        }

        func sharerDidCancel(_ sharer: FBSDKSharing!) {
            print("Cancelled")
        }

    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM