0

I want to check user like a facebook page or not?

Here, My code is,

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

When I execute this code I got "notification.object" like this

Printing description of notification:
NSConcreteNotification 0x7d940e20 {name =  FBSDKLikeActionControllerDidUpdateNotification; object = <FBSDKLikeActionController: 0x7d89cea0>; userInfo = {
animated = 1;
}}
Himanshu Patel
  • 1,015
  • 8
  • 26
  • Did you check http://stackoverflow.com/questions/5329818/seamless-way-to-check-if-user-likes-page – Amanpreet Jan 24 '17 at 05:33
  • @Amanpreet This is not a vaild answer as per my question, And It's in PHP not in Swift – Himanshu Patel Jan 24 '17 at 05:38
  • Oops! I apologies. – Amanpreet Jan 24 '17 at 05:40
  • Look this http://stackoverflow.com/questions/15719701/ios-how-to-check-whether-the-user-likes-a-facebook-page-or-not?rq=1 – Amanpreet Jan 24 '17 at 05:41
  • @Amanpreet Ok, I have checked this link, And I try to implement in my code, But yet I don't understand after my uiwebview loaded how can I check whether the user liked the page or not? – Himanshu Patel Jan 24 '17 at 05:51
  • @Amanpreet Can I like facebook page inside my app? If yes then How? – Himanshu Patel Jan 24 '17 at 05:52
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/133854/discussion-between-himanshu-patel-and-amanpreet). – Himanshu Patel Jan 24 '17 at 05:53
  • I think you need a page_id too. As you can see http://life-optimized.blogspot.in/2013/08/check-if-facebook-page-is-liked-using.html. But its not in swift. – Amanpreet Jan 24 '17 at 06:03
  • @Amanpreet Ok, I try to apply – Himanshu Patel Jan 24 '17 at 06:06
  • Possible duplicate of [FBLikeControl callback](http://stackoverflow.com/questions/26236655/fblikecontrol-callback) – Nikunj Damani Jan 24 '17 at 06:26
  • @Amanpreet Not working. Nothing happend when I call. – Himanshu Patel Jan 24 '17 at 06:44
  • FYI: Facebook does not allow “like gating” in any way, shape or form any more. You would need user_likes permission - but Facebook will not approve that in review, if you try to get it for this purpose. You have to show the same content to people regardless of whether they liked a specific page or not. – CBroe Jan 24 '17 at 10:52
  • @CBroe I have alredy prermission of "user_likes ". When I click on "Facebook Like" button for particular facebook page my 1 like added successfully, After I call notification method "FBSDKLikeActionControllerDidUpdateNotification" for response (If page like success or not). But not working properly. I got response like this, Printing description of notification: NSConcreteNotification 0x7d940e20 {name = FBSDKLikeActionControllerDidUpdateNotification; object = ; userInfo = { animated = 1; }} – Himanshu Patel Jan 24 '17 at 11:01

0 Answers0