SlideShare ist ein Scribd-Unternehmen logo
1 von 23
Installing Facebook Connect Plugin with Phonegap iOS app for beginners
For better readability and screenshots, visit the original blog post link: http://jbkflex.wordpress.com/2013/03/16/installing-facebook-

connect-plugin-with-phonegap-ios-app-for-beginners/


Joseph Khan, March 16,2013


This post has come out of my recent struggle to integrate the Facebook Connect plugin by Dave
Johnson and make it work with my Phonegap iOS app. I had a hard time figuring things out as I was
new to Phonegap iOS development. I was already doing Android apps with Phonegap, but iOS has given
me some tough time. Nevertheless, around 2 days of gloomy and sad face was finally rewarded with a big
smile. So, better I document it somewhere so that I do not struggle again and that’s where the inspiration
for this post lies. And I must say, the official documentation is pathetic for newbies.
Alright, let’s get started. I will go step by step into the process with all details and screenshots so that it is
very easy for you. In this post however, I will not be talking on how to create a Phonegap iOS app, or how
to create Phonegap iOS plugins. For that you still need to look at the official documentation. I will only
discuss on how we can install the Facebook plugin with a Phonegap iOS app and get started using it.
Before moving further I would like to inform you that I am using Phonegap 2.2.0 for my demo. There are
new versions available – 2.5.0 being the latest at the time of writing. So you might want to check
the official pages if you are using the latest version of Phonegap. But the steps mentioned below should
work with the new versions of Phonegap as well. OK, time to start now.
Note: Phonegap and Cordova are the same (well, at least for me..). I prefer calling Phonegap.
1) Do I need a Mac? Simple answer – Yes, you need a Mac. I have heard and read thousand times
about people asking if iOS apps can be developed in a Windows machine. Simply, I just did not research,
instead I have a Mac and I started on it. But the answer is you need a Mac definitely, since you will use
XCode and the iOS SDK for development.
2) Create a Phonegap iOS App - I am using Phonegap 2.2.0. I am not going to show how to create a
Phonegap iOS app. For that look at this pdf documentation here. If you cannot open it, check out
this link which is the pdf source. This should get you started. However I have some screenshots below
which should also help you out.
a) I have created a basic Phonegap app – FacebookPluginTest inside Cordova22FacebookTest folder
under Documents. See the screenshot below. I have used the Terminal to create the app. You can find
details about the command in the document above. So make sure you go through it once.




b) Open the iOS app that you have just created in XCode by double
clicking FacebookPluginTest.xcodeproj. This is how it looks inside XCode. You can see the www folder
where we need to put our html/css/js code.
c) After that test it in a simulator. Here I am running my app in the simulator. If everything goes fine you
can see something similar like the screenshot below.




3) Download the latest Facebook SDK from https://developers.facebook.com/ios/downloads and install
it on your Mac. I am using the SDK3.1.1, but at the time of writing SDK3.2 is available. After installing you
can find the files in Documents folder (in case you did not specify any other folder at the time of install).
See the screenshot below,




4) Create a Facebook app – You have to create a Facebook app. Any interaction with the Facebook API
from your phonegap iOS app happens through an interface that is created by the Facebook app. So
navigate tohttps://developers.facebook.com/apps and create an app. Follow the steps given in point no 4
– Create a Facebook App, from the getting started guide here
– http://developers.facebook.com/docs/getting-started/facebook-sdk-for-ios/
a) Use the Bundle Identifier of your Phonegap iOS project. Find it inside XCode’s Project Summary Page.
It is the reverse domain url/package name that you typed while creating your project. Check out the
screenshot below.




5) Next download the (Dave Jonhson’s) Phonegap Facebook Connect plugin from Github
-https://github.com/phonegap/phonegap-facebook-plugin. Navigate to Github – and clone the repository.
The files will be downloaded to your Mac. After you download you can find the plugin folder structure as
specified in the “Project Structure”section of the Plugin’s Github page (the readme file). It has the
Facebook JavaScript SDK file, iOS Native Facebook Plugin Code and the plugin’s JavaScript interface
code. We will need all of these to integrate with our Phonegap iOS project in XCode. We will see that later
in the post.


6) Now that you have all things in place, let’s see how to integrate the plugin and start using it. If you have
any issues till now, carefully follow the steps above again.


7) We already have created our basic Phonegap iOS project – FacebookPluginTest and it is currently
open inside XCode.


8) Now drag the FacebookSDK.framework folder from the FacebookSDK installation folder (usually
inside Documents) into the Frameworks section of the project navigator inside XCode. See the image
below




With this step we are adding the FacebookSDK API to our Phonegap project. 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. See the image below. After that click on the Finish button
to add the SDK. You can see it inside the Frameworks section of the project navigator inside XCode.
9) Now Add the Facebook SDK for iOS resource bundle by dragging
the FacebookSDKResources.bundle file from theFacebookSDK.framework/Resources folder (under
your Facebook SDK installation folder, usually Documents..) into the Frameworks section of your Project
Navigator inside XCode. Again choose ‘Create groups for any added folders’ and deselect ‘Copy items
into destination group’s folder (if needed)’. See the image below,




10) Add the headers by dragging the DeprecatedHeaders folder from
theFacebookSDK.framework/Versions/A/DeprecatedHeaders folder (under your Facebook SDK
installation folder, usually Documents..) into the Frameworks section of your Project Navigator. Again
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. See the image below,
11) After adding the three frameworks your Frameworks folder in the project navigator should look like the
image below,




For the three steps above you can find more information in the Getting Started Guide -Step
5: “Configure a new XCode Project” from Facebook Developer’s page
– http://developers.facebook.com/docs/getting-started/facebook-sdk-for-ios/
12) The SDK relies on three other frameworks (AdSupport, Accounts and Social) to use the Facebook
features built into iOS6. We need to add these to our project. So click on your project name/icon (the
topmost item in the project navigator) and then click on the project name (FacebookPluginTest for us)
under Targets. See the image below




Then click on the Build Phases tab in the summary page. Open the “Link Binary with Libraries” panel from
the list. See the image below
Click on the (+) icon at the bottom of the panel to add the three frameworks. This will open up a dialog
with the list of all Frameworks. Then type Social in the search input box and this will filter
the Social.framework in the list below. Then add this framework by clicking on the Add button. See the
image below,




Similarly add the other two frameworks – Accounts.framework and AdSupport.framework. Search in
the search box as above and then add it. Make sure you make the three frameworks optional. So use
the ‘Optional’ flag for iOS6-specific frameworks to support older versions of the iOS operating systems.
See the image below,




After adding the three frameworks, the project navigator inside XCode looks like the image below.




You can notice that the frameworks are added under your Project’s name. You can drag the three
frameworks to the Frameworks folder as shown in the image below. Or let it be where it is already, as this
will not create any problem.
13) Now we need to add the SQLite (-lsqlite3.0) SQL Library and -ObjC linker flags to our project in
XCode. Click on the project name in the navigator (topmost item in project navigator) and click the project
name under Project (FacebookPluginTest for us…). After that click on the Build Settings tab. See the
image below,
Search for Other Linker Flags in the search box on the right. See the image below,




Now add the values -lsqlite3.0 and -ObjC to the list. See the image below. (To get the pop up, double
click on the Other Linker Flags..)




After adding it should look like the image below,




14) Now we need to add the Facebook APP ID in our project’s info.plist file. You can find the Facebook
APP ID (if you have already created a Facebook App, if not see step 4 above) from the App summary
page inhttps://developers.facebook.com/apps. See the image below for help




Now Open the Resources folder in your project navigator and select the ProjectName-Info.plist file, for
us it will be theFacebookPluginTest-Info.plist file. Right click on it and select Open As -> Source Code.
See the image below,




Now add the following to the file in the editor panel under the root <dict></dict> tags,
<key>FacebookAppID</key>


<string>Add your APP Id here</string>


<key>CFBundleURLTypes</key>


<array>
<dict>


  <key>CFBundleURLName</key>


  <string>Your scheme id here</string>


  <key>CFBundleURLSchemes</key>


  <array>


   <string>fb[Your APP Id here]</string>


  </array>


 </dict>


</array>


where Scheme Id is usually a unique identifier for the scheme, in reverse domain name notation (i.e
com.facebook.phonegap.myscheme). You can use any name in place of myscheme. See the image
below for help




This step ensures correct re-direct from Mobile Safari or the Facebook app, after permission
authorization. But be sure to use your own Facebook APP ID.
15) Now we will add the Facebook JavaScript SDK file to our Phonegap app. So go to your downloaded
Phonegap Facebook Connect plugin folder and copy facebook_js_sdk.js under lib folder into
the www directory of your project in Xcode. See the two images below
16) Now we will add the Facebook plugin’s native iOS code to our project. So select the two files
(FacebookConnectPlugin.h and FacebookConnectPlugin.m) inside native/ios folder under your
Phonegap Facebook plugin’s downloaded folder and drag the two files and add it to the Plugins folder
inside XCode. Choose ‘Create groups for any added folders’ and deselect ‘Copy items into destination
group’s folder (if needed)’. See the image below,




17) Next step is to add the java script interface of the Facebook plugin’s code. This acts as an interface
for the native iOS plugin code and your html (note that every Facebook plugin has a javascript .js file and
native files which has native code). So open the www folder inside the downloaded Facebook plugin
folder and copy the cdv-plugin-fb-connect.js file into thewww folder of your project inside XCode. See
the image below ,
Now, add the copied file to the www folder of your Phonegap iOS project like you did above when you
added the Facebook java script SDK file.
18) Then we have to register the Facebook Connect plugin in the Plugins list. So open the Resources
folder in the project navigator inside XCode and select Cordova.plist. Then under Plugins section add
the following data – For the key, addorg.apache.cordova.facebook.Connect, and its value will
be FacebookConnectPlugin. See the image below
When it’s done, it should look like the image below




19) After that we will have to add the Facebook domains to the External Host. The Facebook SDK will try
to access various URLs, and their domains must be whitelisted in your Cordova.plist under
ExternalHosts. You can either add each subdomain separately or you can allow all domains by adding
a *. I opted for the later. See the image below,
With that we have successfully set up the Facebook Plugin with our Phonegap iOS app. For testing if
everything is fine, run the app in the simulator. You should see like the image below. We have not tried
the Facebook API yet so you will see the Phonegap ready screen again. But this shows that we have set
up everything correctly. There may be some warning messages but fortunately no compilation or runtime
errors.




Time to run an example now
The Phonegap Facebook Connect plugin comes with two ready to use examples – The Hackbook and
the Simple example. So copy the Hackbook contents from inside the examples folder under the
downloaded Facebook plugin folder and paste it inside the www folder of your Phonegap iOS project.
See the image below,
When there are file conflicts during copying select Replace for all the options.




Now the Hackbook example code is added to your project. Open the index.html file inside XCode for
editing and add the Facebook APP Id to the JavaScript snippet. You can find it inside the callback
function of the device ready event. See the image below. Add your Facebook APP Id in the required
place.




Give a final check. Check if cordova-2.2.0.js, cdv-plugin .js file and the facebook .js sdk file have been
referenced inside individual <script> tags in the index.html file. It should be there. In case you are using a
different Phonegap version make sure to rename the cordova-x.x.x.js file inside index.html to the version
that you are using.
Everything looks fine now. Run the app in the simulator one final time. And Ecstasy!! The Hackbook
example opens up in the simulator. You should see something like the image below,




Now in the Hackbook app, you can login and authorize the app and start using it. You can use the
Facebook Graph API features there. Similarly you can try out the Simple example that ships with the
Phonegap Facebook plugin download. Just copy the files from the downloaded plugin folder to the www
folder of your project. And test the app in the simulator.
From here on you can use the Facebook API to add numerous features to your Phonegap iOS app. I
hope this will be helpful to all the newbies out there. Leave behind a comment below if I missed
something or something was incorrect in this post.

Weitere ähnliche Inhalte

Kürzlich hochgeladen

Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Jeffrey Haguewood
 
Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxRemote DBA Services
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesrafiqahmad00786416
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistandanishmna97
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusZilliz
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamUiPathCommunity
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...apidays
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...apidays
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024The Digital Insurer
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Victor Rentea
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 
Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityWSO2
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...apidays
 
WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businesspanagenda
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdfSandro Moreira
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Orbitshub
 

Kürzlich hochgeladen (20)

Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptx
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital Adaptability
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering Developers
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 

Empfohlen

Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsPixeldarts
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthThinkNow
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfmarketingartwork
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Applitools
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at WorkGetSmarter
 

Empfohlen (20)

Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work
 

Installing Facebook Connect Plugin with Phonegap iOS app for beginners

  • 1. Installing Facebook Connect Plugin with Phonegap iOS app for beginners For better readability and screenshots, visit the original blog post link: http://jbkflex.wordpress.com/2013/03/16/installing-facebook- connect-plugin-with-phonegap-ios-app-for-beginners/ Joseph Khan, March 16,2013 This post has come out of my recent struggle to integrate the Facebook Connect plugin by Dave Johnson and make it work with my Phonegap iOS app. I had a hard time figuring things out as I was new to Phonegap iOS development. I was already doing Android apps with Phonegap, but iOS has given me some tough time. Nevertheless, around 2 days of gloomy and sad face was finally rewarded with a big smile. So, better I document it somewhere so that I do not struggle again and that’s where the inspiration for this post lies. And I must say, the official documentation is pathetic for newbies. Alright, let’s get started. I will go step by step into the process with all details and screenshots so that it is very easy for you. In this post however, I will not be talking on how to create a Phonegap iOS app, or how to create Phonegap iOS plugins. For that you still need to look at the official documentation. I will only discuss on how we can install the Facebook plugin with a Phonegap iOS app and get started using it. Before moving further I would like to inform you that I am using Phonegap 2.2.0 for my demo. There are new versions available – 2.5.0 being the latest at the time of writing. So you might want to check the official pages if you are using the latest version of Phonegap. But the steps mentioned below should work with the new versions of Phonegap as well. OK, time to start now. Note: Phonegap and Cordova are the same (well, at least for me..). I prefer calling Phonegap. 1) Do I need a Mac? Simple answer – Yes, you need a Mac. I have heard and read thousand times about people asking if iOS apps can be developed in a Windows machine. Simply, I just did not research, instead I have a Mac and I started on it. But the answer is you need a Mac definitely, since you will use XCode and the iOS SDK for development. 2) Create a Phonegap iOS App - I am using Phonegap 2.2.0. I am not going to show how to create a Phonegap iOS app. For that look at this pdf documentation here. If you cannot open it, check out this link which is the pdf source. This should get you started. However I have some screenshots below which should also help you out. a) I have created a basic Phonegap app – FacebookPluginTest inside Cordova22FacebookTest folder under Documents. See the screenshot below. I have used the Terminal to create the app. You can find
  • 2. details about the command in the document above. So make sure you go through it once. b) Open the iOS app that you have just created in XCode by double clicking FacebookPluginTest.xcodeproj. This is how it looks inside XCode. You can see the www folder where we need to put our html/css/js code.
  • 3. c) After that test it in a simulator. Here I am running my app in the simulator. If everything goes fine you can see something similar like the screenshot below. 3) Download the latest Facebook SDK from https://developers.facebook.com/ios/downloads and install it on your Mac. I am using the SDK3.1.1, but at the time of writing SDK3.2 is available. After installing you can find the files in Documents folder (in case you did not specify any other folder at the time of install). See the screenshot below, 4) Create a Facebook app – You have to create a Facebook app. Any interaction with the Facebook API from your phonegap iOS app happens through an interface that is created by the Facebook app. So
  • 4. navigate tohttps://developers.facebook.com/apps and create an app. Follow the steps given in point no 4 – Create a Facebook App, from the getting started guide here – http://developers.facebook.com/docs/getting-started/facebook-sdk-for-ios/ a) Use the Bundle Identifier of your Phonegap iOS project. Find it inside XCode’s Project Summary Page. It is the reverse domain url/package name that you typed while creating your project. Check out the screenshot below. 5) Next download the (Dave Jonhson’s) Phonegap Facebook Connect plugin from Github -https://github.com/phonegap/phonegap-facebook-plugin. Navigate to Github – and clone the repository. The files will be downloaded to your Mac. After you download you can find the plugin folder structure as specified in the “Project Structure”section of the Plugin’s Github page (the readme file). It has the Facebook JavaScript SDK file, iOS Native Facebook Plugin Code and the plugin’s JavaScript interface code. We will need all of these to integrate with our Phonegap iOS project in XCode. We will see that later in the post. 6) Now that you have all things in place, let’s see how to integrate the plugin and start using it. If you have any issues till now, carefully follow the steps above again. 7) We already have created our basic Phonegap iOS project – FacebookPluginTest and it is currently open inside XCode. 8) Now drag the FacebookSDK.framework folder from the FacebookSDK installation folder (usually inside Documents) into the Frameworks section of the project navigator inside XCode. See the image
  • 5. below With this step we are adding the FacebookSDK API to our Phonegap project. 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. See the image below. After that click on the Finish button to add the SDK. You can see it inside the Frameworks section of the project navigator inside XCode.
  • 6. 9) Now Add the Facebook SDK for iOS resource bundle by dragging the FacebookSDKResources.bundle file from theFacebookSDK.framework/Resources folder (under your Facebook SDK installation folder, usually Documents..) into the Frameworks section of your Project Navigator inside XCode. Again choose ‘Create groups for any added folders’ and deselect ‘Copy items into destination group’s folder (if needed)’. See the image below, 10) Add the headers by dragging the DeprecatedHeaders folder from theFacebookSDK.framework/Versions/A/DeprecatedHeaders folder (under your Facebook SDK installation folder, usually Documents..) into the Frameworks section of your Project Navigator. Again 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. See the image below,
  • 7. 11) After adding the three frameworks your Frameworks folder in the project navigator should look like the image below, For the three steps above you can find more information in the Getting Started Guide -Step 5: “Configure a new XCode Project” from Facebook Developer’s page – http://developers.facebook.com/docs/getting-started/facebook-sdk-for-ios/ 12) The SDK relies on three other frameworks (AdSupport, Accounts and Social) to use the Facebook features built into iOS6. We need to add these to our project. So click on your project name/icon (the
  • 8. topmost item in the project navigator) and then click on the project name (FacebookPluginTest for us) under Targets. See the image below Then click on the Build Phases tab in the summary page. Open the “Link Binary with Libraries” panel from the list. See the image below
  • 9. Click on the (+) icon at the bottom of the panel to add the three frameworks. This will open up a dialog with the list of all Frameworks. Then type Social in the search input box and this will filter the Social.framework in the list below. Then add this framework by clicking on the Add button. See the image below, Similarly add the other two frameworks – Accounts.framework and AdSupport.framework. Search in the search box as above and then add it. Make sure you make the three frameworks optional. So use the ‘Optional’ flag for iOS6-specific frameworks to support older versions of the iOS operating systems.
  • 10. See the image below, After adding the three frameworks, the project navigator inside XCode looks like the image below. You can notice that the frameworks are added under your Project’s name. You can drag the three frameworks to the Frameworks folder as shown in the image below. Or let it be where it is already, as this will not create any problem.
  • 11. 13) Now we need to add the SQLite (-lsqlite3.0) SQL Library and -ObjC linker flags to our project in XCode. Click on the project name in the navigator (topmost item in project navigator) and click the project name under Project (FacebookPluginTest for us…). After that click on the Build Settings tab. See the image below,
  • 12. Search for Other Linker Flags in the search box on the right. See the image below, Now add the values -lsqlite3.0 and -ObjC to the list. See the image below. (To get the pop up, double click on the Other Linker Flags..) After adding it should look like the image below, 14) Now we need to add the Facebook APP ID in our project’s info.plist file. You can find the Facebook APP ID (if you have already created a Facebook App, if not see step 4 above) from the App summary
  • 13. page inhttps://developers.facebook.com/apps. See the image below for help Now Open the Resources folder in your project navigator and select the ProjectName-Info.plist file, for us it will be theFacebookPluginTest-Info.plist file. Right click on it and select Open As -> Source Code. See the image below, Now add the following to the file in the editor panel under the root <dict></dict> tags, <key>FacebookAppID</key> <string>Add your APP Id here</string> <key>CFBundleURLTypes</key> <array>
  • 14. <dict> <key>CFBundleURLName</key> <string>Your scheme id here</string> <key>CFBundleURLSchemes</key> <array> <string>fb[Your APP Id here]</string> </array> </dict> </array> where Scheme Id is usually a unique identifier for the scheme, in reverse domain name notation (i.e com.facebook.phonegap.myscheme). You can use any name in place of myscheme. See the image below for help This step ensures correct re-direct from Mobile Safari or the Facebook app, after permission authorization. But be sure to use your own Facebook APP ID.
  • 15. 15) Now we will add the Facebook JavaScript SDK file to our Phonegap app. So go to your downloaded Phonegap Facebook Connect plugin folder and copy facebook_js_sdk.js under lib folder into the www directory of your project in Xcode. See the two images below
  • 16. 16) Now we will add the Facebook plugin’s native iOS code to our project. So select the two files (FacebookConnectPlugin.h and FacebookConnectPlugin.m) inside native/ios folder under your Phonegap Facebook plugin’s downloaded folder and drag the two files and add it to the Plugins folder inside XCode. Choose ‘Create groups for any added folders’ and deselect ‘Copy items into destination group’s folder (if needed)’. See the image below, 17) Next step is to add the java script interface of the Facebook plugin’s code. This acts as an interface for the native iOS plugin code and your html (note that every Facebook plugin has a javascript .js file and native files which has native code). So open the www folder inside the downloaded Facebook plugin folder and copy the cdv-plugin-fb-connect.js file into thewww folder of your project inside XCode. See the image below ,
  • 17. Now, add the copied file to the www folder of your Phonegap iOS project like you did above when you added the Facebook java script SDK file. 18) Then we have to register the Facebook Connect plugin in the Plugins list. So open the Resources folder in the project navigator inside XCode and select Cordova.plist. Then under Plugins section add the following data – For the key, addorg.apache.cordova.facebook.Connect, and its value will be FacebookConnectPlugin. See the image below
  • 18. When it’s done, it should look like the image below 19) After that we will have to add the Facebook domains to the External Host. The Facebook SDK will try to access various URLs, and their domains must be whitelisted in your Cordova.plist under ExternalHosts. You can either add each subdomain separately or you can allow all domains by adding a *. I opted for the later. See the image below,
  • 19. With that we have successfully set up the Facebook Plugin with our Phonegap iOS app. For testing if everything is fine, run the app in the simulator. You should see like the image below. We have not tried the Facebook API yet so you will see the Phonegap ready screen again. But this shows that we have set up everything correctly. There may be some warning messages but fortunately no compilation or runtime
  • 20. errors. Time to run an example now The Phonegap Facebook Connect plugin comes with two ready to use examples – The Hackbook and the Simple example. So copy the Hackbook contents from inside the examples folder under the downloaded Facebook plugin folder and paste it inside the www folder of your Phonegap iOS project. See the image below,
  • 21.
  • 22. When there are file conflicts during copying select Replace for all the options. Now the Hackbook example code is added to your project. Open the index.html file inside XCode for editing and add the Facebook APP Id to the JavaScript snippet. You can find it inside the callback function of the device ready event. See the image below. Add your Facebook APP Id in the required place. Give a final check. Check if cordova-2.2.0.js, cdv-plugin .js file and the facebook .js sdk file have been referenced inside individual <script> tags in the index.html file. It should be there. In case you are using a different Phonegap version make sure to rename the cordova-x.x.x.js file inside index.html to the version
  • 23. that you are using. Everything looks fine now. Run the app in the simulator one final time. And Ecstasy!! The Hackbook example opens up in the simulator. You should see something like the image below, Now in the Hackbook app, you can login and authorize the app and start using it. You can use the Facebook Graph API features there. Similarly you can try out the Simple example that ships with the Phonegap Facebook plugin download. Just copy the files from the downloaded plugin folder to the www folder of your project. And test the app in the simulator. From here on you can use the Facebook API to add numerous features to your Phonegap iOS app. I hope this will be helpful to all the newbies out there. Leave behind a comment below if I missed something or something was incorrect in this post.