iOS Facebook分享视频Swift



我正在寻找一种在Facebook上分享我的应用程序视频的方法。我在facebook上安装了SDK并按照说明操作,但我不明白为什么我不能分享我的视频。

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

参数委托有一个错误:

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

请注意,我在我的类ShareViewController。

没有其他方法可以在facebook上分享视频吗?谢谢你

方法showFromViewController:withContent:delegate:期望委托参数类型为FBSDKSharingDelegate。你正在提供类型ShareViewController而不是FBSDKSharingDelegate的值,这意味着说视图控制器不符合该类型。你需要使你的视图控制器符合类型FBSDKSharingDelegate。例如:

class ShareViewController: UIViewController, FBSDKSharingDelegate {
    // code
}

或者传入另一个符合FBSDKSharingDelegate类型的对象。

你必须实现FBSDKSharingDelegate协议和它的方法。

    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")
        }
    }

最新更新