Swift 3.0,如何检查用户是否喜欢facebook页面?

时间:2017-01-24 05:29:01

标签: ios swift facebook-graph-api facebook-like

我想检查用户是否像Facebook页面一样?

下面, 我的代码是,

override func viewDidLoad() {
    super.viewDidLoad()
    // Do any additional setup after loading the view, typically from a nib.

    let likeButton = FBSDKLikeControl()
    likeButton.objectID = "https://www.facebook.com/IntelIndia/"
    likeButton.center = self.view.center
    likeButton.likeControlStyle = FBSDKLikeControlStyle.boxCount
    likeButton.likeControlHorizontalAlignment = FBSDKLikeControlHorizontalAlignment.right
    self.view.addSubview(likeButton)
}

override func viewWillAppear(_ animated: Bool) {
    super.viewWillAppear(animated)

    NotificationCenter.default.addObserver(self, selector: #selector(self.likeActionPerformed), name: NSNotification.Name(rawValue: "FBSDKLikeActionControllerDidUpdateNotification"), object: nil)
}

override func viewWillDisappear(_ animated: Bool) {
    super.viewWillDisappear(animated)

    NotificationCenter.default.removeObserver(self)
}

func likeActionPerformed(notification: NSNotification) {
    print("\(notification.object)")
}

当我执行此代码时,我得到了“notification.object”,就像这样

Printing description of notification:
NSConcreteNotification 0x7d940e20 {name =  FBSDKLikeActionControllerDidUpdateNotification; object = <FBSDKLikeActionController: 0x7d89cea0>; userInfo = {
animated = 1;
}}

0 个答案:

没有答案