FBLikeControl Callback

Is there any way to get some feedback from the new FBLikeControl if the user liked the page? Or at least somehow know that he was back in the app from the Facebook app?

+4
source share
4 answers

Update:

Since Facebook explicitly made this header private, now you need to subscribe directly to the notification using the raw string:

[[NSNotificationCenter defaultCenter] addObserver:myObject selector:@selector(myCallback:) name:@"FBLikeActionControllerDidUpdateNotification"];

Old answer for reference:

For those who are looking for this in the future: I have finished subscribing to FBLikeActionControllerDidUpdateNotification notifications. After receiving the notification, you can do the following:

if ([notification.object isKindOfClass:[FBLikeActionController class]]) {
    if ([(FBLikeActionController*)notification.object objectIsLiked]) {
       // do your stuff here, user liked!
    }
}
+6
source

FBLikeActionController.h , , :

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(facebookLikeNotification:) name:@"FBLikeActionControllerDidUpdateNotification" object:nil];

. lldb pragmas undefined:

    - (void)facebookLikeNotification:(NSNotification*)notification {
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wundeclared-selector"
    SEL selector = @selector(objectIsLiked);
    if (notification.object && [notification.object respondsToSelector:selector]) {

        BOOL (*BOOLMsgSend)(id, SEL) = (typeof(BOOLMsgSend)) objc_msgSend;
        BOOL isLiked = BOOLMsgSend(notification.object, selector);
        DDLogDebug(@"is liked: %d",isLiked);

    }
#pragma clang diagnostic pop
}
+3

, ( , ), , [likeButton addTarget:self action:@selector(yourCallbackFunction:) forControlEvents:UIControlEventValueChanged]; yourCallbackFuntion: , .

,

+1
source

A small gift for those who are faced with this problem:

  • Import #import <FBSDKCoreKit/FBSDKMacros.h>
  • Define the nofitication key FBSDK_EXTERN NSString *const FBSDKLikeActionControllerDidUpdateNotification;
  • Register Notification [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onLikeActionControllerDidUpdateNotification) name:FBSDKLikeActionControllerDidUpdateNotification object:nil];

And a notification will be triggered whenever a user makes a change to a button LIKE(for example, or as opposed to).

+1
source

All Articles