Reputation: 1723
My application requires a "Like Us on Facebook" functionality.I tried to use Facebook SDK and the "FBLikecontrol" of the SDK.This is the code i tried:
FBLikeControl *likeControl = [[FBLikeControl alloc] initWithFrame:CGRectMake(138, 270, 180, 40)];
[likeControl setObjectID:@"facebook page url"];
[likeControl setLikeControlStyle:FBLikeControlStyleStandard];
[[self view] addSubview:likeControl];
On running on the device(iOS7),when clicked on the like button,app redirects to the safari Facebook page and suddenly redirects backs to the app.Facebook page or nothing is showing.Can anyone help on this? Thanks in advance!
Upvotes: 1
Views: 3221
Reputation: 1510
4.28.0 - November 7, 2017 Facebook SDK The Native Like Button has been deprecated. link
Upvotes: 0
Reputation: 845
I am follow these steps and its working...
Step 1- Add Facebook button to your view
FBLikeControl *like = [[FBLikeControl alloc] init];
like.objectID = @"https://www.facebook.com/{sub url}";
like.likeControlStyle = FBLikeControlStyleButton;
like.objectType = FBLikeControlObjectTypePage;
cell.accessoryView = like;
Step 2- Send for Review (Important Step) Native Like button will work if you submit it for review from Facebook app. Go to your Facebook app page --> Status and Review and send like button for review.
if you are not follow second step you will face redirect problem.
Upvotes: 4
Reputation: 995
I tried your provided code in my Sample Application it working fine
FBLikeControl *fbLikeControlView = [[FBLikeControl alloc] initWithFrame:CGRectMake(100, 100, 200, 30)];
fbLikeControlView.likeControlStyle = FBLikeControlStyleStandard;
fbLikeControlView.objectID=@"https://www.example.com/";
[self.view addSubview:fbLikeControlView];
My code is same as on facebook developer site Like Button iOS
Also don't forget to handle openURL method in Appdelegate
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {
// Call FBAppCall's handleOpenURL:sourceApplication to handle Facebook app responses
BOOL wasHandled = [FBAppCall handleOpenURL:url sourceApplication:sourceApplication];
// You can add your app-specific url handling code here if needed
return wasHandled;
}
Upvotes: 4