This plugin is mainly a fork of @phonegap/phonegap-facebook-plugin and it is accomodated for Phonegap >=3.0, and cleaned up a little bit, and accomodated for our needs. So it is not official, and we cannot guarantee it will work properly for your needs. It does not include Facebook SDK. Supports Android and iOS.
ANDROID
First you will need Facebook SDK
Then you need to include the SDK into your Ant build: edit your local.properties
file and add
android.library.reference.1=../relative/path/to/facebook-android-sdk-3.5.2/facebook/
Then add the plugin to your phonegap project:
phonegap local plugin add https://github.com/bait-sk/cordova-plugin-facebook.git
iOS
- Download the latest Facebook SDK for iOS from the iOS Dev Center.
- 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)'
- Add the headers by dragging the DeprecatedHeaders folder from the FacebookSDK.framework/Versions/A/DeprecatedHeaders 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)'. This adds the headers as a reference.
- Click on your project's icon (the root element) in Project Navigator, select your Project, then the Build Settings tab, search for Other Linker Flags.
- Add the value -lsqlite3.0
- Add the value -ObjC
- Click on your project's icon (the root element) in Project Navigator, select your Target, then the Build Phases tab, then the Link Binary With Libraries option.
- Add the Social.framework framework. Make it an optional framework to support pre iOS6 apps.
- Add the Accounts.framework framework. Make it an optional framework to support pre iOS6 apps.
- Add the AdSupport.framework framework. Make it an optional framework to support pre iOS6 apps.
- Add the Security.framework framework. Make it an optional framework to support pre iOS6 apps.
Then add the plugin to your phonegap project:
phonegap local plugin add https://github.com/bait-sk/cordova-plugin-facebook.git
Then you will need to update your *-Info.plist
file of the project and add following parameters:
<FacebookAppID>
<string>$APP_ID</string>
</FacebookAppID>
<FacebookDisplayName>
<string>$APP_NAME</string>
</FacebookDisplayName>
<CFBundleURLTypes>
<dict>
<key>CFBundleURLSchemes</key>
<array>
<string>fb$APP_ID</string>
</array>
</dict>
</CFBundleURLTypes>
Replacing $VARS with respective values.
For now the JS files provided aren't exported as global modules, so you have to include both cdv-plugin-fb-connect.js
and facebook-js-sdk.js
as script
tags.
Initialize plugin upon deviceready
event, replace 1234567890123456789
with your facebook app id.
document.addEventListener('deviceready', function() {
try {
alert('Device is ready! Make sure you set your app_id below this alert.');
FB.init({ appId: "1234567890123456789", nativeInterface: CDV.FB, useCachedDialogs: false });
document.getElementById('data').innerHTML = "";
} catch (e) {
alert(e);
}
}, false);