Facebook like button in iOS app using Facebook SDK

2019-06-04 04:34发布

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!

3条回答
smile是对你的礼貌
2楼-- · 2019-06-04 04:51

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

查看更多
爷的心禁止访问
3楼-- · 2019-06-04 05:06

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;
}
查看更多
三岁会撩人
4楼-- · 2019-06-04 05:09

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.

查看更多
登录 后发表回答