Facebook SDK on Cocos2D-X

  • Name:Facebook SDK on Cocos2D-X
  • Author:Jesus Bosch
  • Code Repository:
  • Last Update:2013-04-09
  • Compatible with:
  • Platform:
  • API Language:
  • Website:
  • Company: Plunge Interactive


Using the native Facebook SDK on Cocos2D-X iOS projects


Facebook integration is something common on any mobile game today. In order to do so, we need to remember that the iOS Facebook SDK is written in Objective-C. So in my opinion, the easiest way to communicate between Cocos2D-X and Facebook is using the native Objective-C based Facebook SDK for iOS, with no inventions.

This will allow us a deep integration between our game and Facebook. The bad side is obviously that if we want to go cross platform, for instance on Android, we will need to implement the Facebook “bridge” for Android with the Java SDK too. But nobody said that making cross-platform games was going to be easy right? And if they did they are liars :~~)
This guide is not going to be useful for the Facebook integration only, it will work on any Objective-C native library, so we can get the full power of the native platform libraries .
Ok then, the first thing we need to do is to setup our app on Facebook. I’ll not going to explain this into detail, the Facebook Developers website has a great tutorial that does the job. Please follow these steps:
h1. Create a Cocos2D-X project on XCode :~~)
h2. (facebook tutorial) Step 1: Registering your iOS App with Facebook
h3. (facebook tutorial) Step 2: Installing the iOS SDK. You must then copy the downloaded SDK into our “libs” folder in our XCode project.
(facebook tutorial) Modify the app property list file as specified in the tutorial.
After following those steps, we are ready to get access to Facebook from our C*+ code. We just need to create a bridge between C*+ and Objective-C. I have already explained this part in a previous post, so please, read it.

Ok, if you have followed the steps carefully, you will probably notice about two important problems:

The Facebook delegates will not be fired if you call the Facebook API from a common Objective-C*+ file. I am talking about login result delegates and so on.
How do I callback to my C*+ code once I have the execution? For instance, if I want to send a message to C++ informing about if the user has or has not logged in into Facebook, or if he has accepted the permissions request


Sign up for our newsletter to keep up with the latest developments, releases and updates for Cocos2d-x.