Facebook like button in iOS app using Facebook SDK

2019-06-04 04:52发布

问题:

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!

回答1:

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;
}


回答2:

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.



回答3:

4.28.0 - November 7, 2017 Facebook SDK The Native Like Button has been deprecated. link