cmi cmi - 1 year ago 284
Swift Question

Add Facebook like button iOS SWIFT

I'm trying to add the like button in my iOS Swift app, following the Facebook tutorial

I use Pods and a Bridging Header file to add the FB framework:

pod 'FBSDKCoreKit', '~> 4.11'
pod 'FBSDKShareKit'


#ifndef isam_Bridging_Header_h
#define isam_Bridging_Header_h

#import <FBSDKCoreKit/FBSDKCoreKit.h>
#import <FBSDKShareKit/FBSDKShareKit.h>

I updated the plist with the App Facebook ID

enter image description here

Then, in my viewDidLoad I added:

let likeButton:FBSDKLikeControl = FBSDKLikeControl()
likeButton.objectID = ""
likeButton.frame = mailButton.frame
likeButton.likeControlStyle = .BoxCount

The like button is displayed but when I press on it, nothing happens.
I don't understand what I miss



func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {

//Do stuff

FBSDKApplicationDelegate.sharedInstance().application(application, didFinishLaunchingWithOptions: launchOptions)
return true

func application(application: UIApplication,openURL url: NSURL,sourceApplication: String?,annotation: AnyObject) -> Bool {
return FBSDKApplicationDelegate.sharedInstance().application(application,openURL: url,sourceApplication: sourceApplication, annotation: annotation)

func applicationDidBecomeActive(application: UIApplication) {

//Do stuff



override func viewDidLoad() {

//Do stuff

let likeButton:FBSDKLikeControl = FBSDKLikeControl()
likeButton.objectID = ""
likeButton.likeControlStyle = .BoxCount

cmi cmi
Answer Source

In the info.plist :

  • it's FacebookAppID (and not FacebookAppId)
  • remove the "fb" in the FacebookAppID string (set the string just with the numbers)

To debug my Facebook like button, I had to add a login Facebook button in my view controller to have the Facebook logs in the console.


#import <FBSDKLoginKit/FBSDKLoginKit.h>

and using:

let loginButton:FBSDKLoginButton = FBSDKLoginButton() =

Then the logs with my mistakes appeared.

After correcting them, I removed the Facebook login button, and the like button works well!