Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

FBLikeControl callback

is there any way I can get some kind of feedback from the new FBLikeControl if the user liked the page? Or at least to know somehow, that he returned back to the app from the Facebook app?

like image 449
Tim Specht Avatar asked Dec 19 '22 10:12

Tim Specht


2 Answers

Update:

Since Facebook apparently made this header private, you now have to subscribe directly to the notification using a raw string:

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

Old answer for reference:

For anyone in the future looking for this: I ended up subscribing myself to FBLikeActionControllerDidUpdateNotification notifications. Once the notification is received you can do the following:

if ([notification.object isKindOfClass:[FBLikeActionController class]]) {
    if ([(FBLikeActionController*)notification.object objectIsLiked]) {
       // do your stuff here, user liked!
    }
}
like image 171
Tim Specht Avatar answered Jan 08 '23 07:01

Tim Specht


Because the FBLikeActionController.h is a private header, you can get around that by listening to notification string:

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

And handling the notification using selectors. I added lldb pragmas to suppress undefined selector warnings:

    - (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
}
like image 30
Kevin Avatar answered Jan 08 '23 08:01

Kevin