The Facebook SDK for iOS is designed to be easy to install and use. This guide walks through the basics of setting up the development and project environment and creating a simple app.
Watch the screencast or follow the steps below.
Download and install the Facebook SDK for iOS
Download the SDK here and install the package. The default install location is
Source code for the SDK is also available on GitHub. If you have Git installed, you can create a local repository by cloning it to a location of your choice:
git clone git://github.com/facebook/facebook-ios-sdk.git
Note: when building the SDK from source, run
scripts/build_framework.sh before compiling and running the samples.
Try the sample projects in the
Samples folder of the installed SDK
The SDK includes a number of samples. Each demonstrates an important features of the SDK and techniques for building social apps.
The following samples are available in the SDK. Simply open the Xcode project files inside each of the folders.
You will need a Facebook App ID before you create a new project with the SDK
Create a new app on the Facebook App Dashboard, enter your app's basic information.
Once created, note the app ID shown at the top of the dashboard page.
You can also use the App ID of an existing app.
Now, you need to set the Bundle Identifier and configure your Facebook application to support login from an iOS application.
Click on the checkmark next to “Native iOS App” and supply your Bundle Identifier in the “Bundle ID” field. In addition, make sure the Facebook Login radio button is set to “Enabled”.
You can find or set your Bundle Identifier in Xcode in the Project tab.
Create a new Xcode project, add the Facebook SDK for iOS, its dependencies, and the Facebook App ID to its settings
In Xcode, create a new project, and select 'Single View Application' as shown below.
Provide a name and identifier as required:
Add the Facebook SDK for iOS Framework by dragging the
FacebookSDK.framework folder from the SDK installation folder into the Frameworks section of your Project Navigator.
Choose 'Create groups for any added folders' and deselect 'Copy items into destination group's folder (if needed)' to keep the reference to the SDK installation folder, rather than creating a copy.
Add the Facebook SDK for iOS resource bundle by dragging the
FacebookSDKResources.bundle file from the
FacebookSDK.framework/Resources folder into the Frameworks section of your Project Navigator.
As you did when copying the Framework, choose 'Create groups for any added folders' and deselect 'Copy items into destination group's folder (if needed)'
You can also add the
FBUserSettingsViewResources bundle in the same way if you expect to use that controller in your app.
The SDK relies on five other frameworks and libraries (AdSupport, Accounts, libsqlite3, Security and Social) to use the Facebook features built into iOS6. To add these, go to the 'Linked Frameworks and Libraries' section of the target's Summary pane, and click the 'plus' button to add them:
Note: You should use the 'Optional' flag for iOS6-specific frameworks if you would like your app to also build for older versions of the operating systems.
Once done, your Project Navigator should look something like this:
Finally, you need to place the Facebook app ID in two places in your application's main
.plist file, and add a reference to your app's Display Name. Create a key called
FacebookAppID with a string value, and add the app ID there. Next, create a key called
FacebookDisplayName with a string value, and add the Display Name you configured in the App Dashboard.
Create an array key called
URL types with a single array sub-item called
URL Schemes. Give this a single item with your app ID prefixed with
fb. This is used to ensure the application will receive the callback URL of the web-based OAuth flow.
.plist should look something like this:
Get started by enhancing one of the sample apps, or working through the Scrumptious Tutorial