Step 1: Install the SDK
You can install the SDK manually or via CocoaPods
. The latter option is highly recommended.
Put these lines in Podfile
:
target 'MyApp' do
use_frameworks!
pod 'FBSDKCoreKit'
pod 'FBSDKLoginKit'
pod 'FBSDKShareKit'
end
Run pod install
in the terminal and open .xcworkspace
instead of .xcodeproj
afterwards.
FBSDKLoginKit
and FBSDKShareKit
are optional. You may or may not need them.
Step 2: Create an app on Facebook
Go to Quick Starts - Facebook for Developers to create an app.
Facebook will ask you to download the SDK after creating the app. You can skip this part if you installed the SDK via CocoaPods already.
Step 3: Edit .plist
.plist
file. Facebook will give you the customized snippet on the Quick Starts page..plist
file as source code.<dict>
tag. Your source code should be something like:<plist version="1.0">
<dict>
// ...
//some default settings
// ...
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleURLSchemes</key>
<array>
<string>fb{FBAppId}</string>
</array>
</dict>
</array>
<key>FacebookAppID</key>
<string>{FBAppId}</string>
<key>FacebookDisplayName</key>
<string>{FBAppName}</string>
<key>LSApplicationQueriesSchemes</key>
<array>
<string>fbapi</string>
<string>fb-messenger-api</string>
<string>fbauth2</string>
<string>fbshareextension</string>
</array>
<key>NSAppTransportSecurity</key>
<dict>
<key>NSExceptionDomains</key>
<dict>
<key>facebook.com</key>
<dict>
<key>NSIncludesSubdomains</key>
<true/>
<key>NSExceptionRequiresForwardSecrecy</key>
<false/>
</dict>
<key>fbcdn.net</key>
<dict>
<key>NSIncludesSubdomains</key>
<true/>
<key>NSExceptionRequiresForwardSecrecy</key>
<false/>
</dict>
<key>akamaihd.net</key>
<dict>
<key>NSIncludesSubdomains</key>
<true/>
<key>NSExceptionRequiresForwardSecrecy</key>
<false/>
</dict>
</dict>
</dict>
</plist>
If you paste the snippet at a wrong place, you will run into problems.
Step 4: Tell Facebook your bundle identifier on the Quick Starts page.
=> How to get bundle identifier
Step 5: Edit your AppDelegate.swift