iOS Facebook分享视频Swift

时间:2016-09-18 20:50:26

标签: ios swift facebook facebook-graph-api facebook-sdk-4.0

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

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

参数delegate我有一个错误:

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

请注意,我在我的班级ShareViewController。

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

2 个答案:

答案 0 :(得分:1)

方法showFromViewController:withContent:delegate:期望委托参数的类型为FBSDKSharingDelegate。您提供的类型为ShareViewController而不是FBSDKSharingDelegate,这意味着所述视图控制器不符合该类型。您需要使视图控制器符合类型FBSDKSharingDelegate。举个例子:

class ShareViewController: UIViewController, FBSDKSharingDelegate {
    // code
}

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

答案 1 :(得分:0)

您必须实现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")
        }

    }