Getting Started with the Facebook SDK for iOS

cakeexoticInternet and Web Development

Dec 13, 2013 (3 years and 6 months ago)

199 views

developers
Prashant Sridharan
github.com/CoolAssPuppy
@CoolAssPuppy
Getting Started with the
Facebook SDK for iOS
Friday, April 19, 13
Getting the SDK
http://developers.facebook.com/ios
Friday, April 19, 13
Why Should You Use the Facebook SDK?
Personalize your
apps using
Facebook data and
get better
engagement
Drive re-
engagement by
publishing
interesting stories
from your apps
Enable users to
more easily
discover your apps
through sharing
Friday, April 19, 13
The Facebook SDK for iOS
Core
FBLoginView
FBGraphObject
FBSession
FBFriendPickerViewController
FBDialogs
FBOpenGraphAction
facade (e.g. FBGraphUser)
FBRequest
FBRequestConnection
Native UI
Graph
FBSettings
Friday, April 19, 13
Facebook Native User Interface
Facebook Login
Profile Picture
Friend Picker
Place Picker
Friday, April 19, 13
Getting Started with the Facebook SDK
!
"
#
$
Create a Facebook app
developers.facebook.com
Add the Facebook SDK to your Xcode project
Configure your Xcode project for Facebook
Start sharing, implement Facebook Login,
publish to Facebook Open Graph
Friday, April 19, 13
Friday, April 19, 13
Why Sharing Matters
Sharing is central to our
online experience...
...and is an expectation
we have from our apps
Friday, April 19, 13
Sharing
Good
Native iOS !
Simplest form of sharing
Does not require Login
Better
Uses latest version of the
installed Facebook app
Does not require Login
Best
Uses actions/objects
generated by apps
Requires Login
Deeply engaging stories
Friday, April 19, 13
[
FBDialogs

presentOSIntegratedShareDialogModallyFrom
:
self

initialText
:
@"This is actually not permitted"

image
:[
UIImage

imageNamed
:
@"image.jpg"
]

url
:[
NSURL

URLWithString
:
@"
http://yoururl.com
"
]

handler
:^(
FBOSIntegratedShareDialogResult
result,
NSError
*error){ }];
Friday, April 19, 13
Demo: Built-In Share Sheet
https://github.com/CoolAssPuppy/ios-GettingStarted
Friday, April 19, 13
Better Sharing with the Facebook SDK for iOS !."

Uses the Facebook App

No Facebook Login required

Explicit sharing to Timeline

Tag friends and places

Supports app attribution

Supports Open Graph

Results in more engaging
stories with minimal additional
development effort
Friday, April 19, 13
[
FBDialogs

presentShareDialogWithLink
:[
NSURL

URLWithString
:
@"
http://yoururl.com/
"
]

handler
:^(
FBAppCall
*call,
NSDictionary
*results,
NSError
*error) { }];
Friday, April 19, 13
NSMutableDictionary
<
FBOpenGraphObject
> *trail = [
FBGraphObject

openGraphObjectForPost
];
trail[
@"type"
] =
@"snsocialhiking:trail"
;
trail[
@"title"
] =
@"The Peak Hike"
;
trail[
@"description"
] =
@"Perfect in the winter, summer, all year"
;
trail[
@"data"
] =
@{

@"location"
:
@{
@"latitude"
:
@"48.515414"
,

@"longitude"
:
@"-120.707605"
,

}

}
;
trail.
provisionedForPost
=
YES
;

// create a place to be tagged with this story
id
<
FBGraphPlace
> place = (
id
<
FBGraphPlace
>)[
FBGraphObject

graphObject
];
[place
setId
:
@"11092928401"
];

id
<
FBOpenGraphAction
> action = (
id
<
FBOpenGraphAction
>)
[
FBGraphObject

openGraphActionForPost
];
[action
setObject
:trail
forKey
:
@"trail"
];
// object tag
[action
setPlace
:place];
// place tag
[action
setTags
:
@[
@"1683794025"
]
];
// user tags

// temporary line of code required
// this will only work in debug mode
// you cannot ship this code yet
[
FBSettings

enableBetaFeature
:
FBBetaFeaturesOpenGraphShareDialog
];

[
FBDialogs

presentShareDialogWithOpenGraphAction
:action

actionType
:
@"snsocialhiking:hike"

previewPropertyName
:
@"trail"

handler
:^(
FBAppCall
*call,
NSDictionary
*results,
NSError
*error)
{ }];
!
Configure your object
"
Configure your action
#
Present the dialog box
Friday, April 19, 13
Beautiful Stories > Better Engagement > Discovery
Friday, April 19, 13
Demo: Native Share Dialogs
Friday, April 19, 13
Driving Better Discovery: Deep Linking
Users see stories generated
by your app in their News
Feed and engage with them
Directed to App Store
to download app if
it’s not installed
Users see stories
generated by
your app in their
News Feeds
Taken directly to
app if the app is
already installed
Friday, April 19, 13
Deep Linking Works Best With Incoming Links
Friday, April 19, 13
-(
BOOL
)application:(
UIApplication
*)application
openURL:(
NSURL
*)url
sourceApplication:(
NSString
*)sourceApplication
annotation:(
id
)annotation
{
[
FBAppCall

handleOpenURL
:url

sourceApplication
:sourceApplication

fallbackHandler
:^(
FBAppCall
*call) {

NSLog
(
@"Returned to Social Boarding with these parameters: %@"
,

call.
appLinkData
.
targetURL
);
}];


return

true
;
}
!
Parse the incoming URL string
"
Parse the target_url parameter
Friday, April 19, 13
Why Use Facebook Login?
User’s identity
Appearing in Search
User’s friends
Getting Distribution
Friday, April 19, 13
// add this to viewDidLoad:

self
.
loginView
.
readPermissions
=
@[
@"email"
,
@"user_likes"
]
;

self
.
loginView
.
delegate
=
self
;
// FBLoginViewDelegate
-(
void
)loginViewFetchedUserInfo:(
FBLoginView
*)loginView
user:(
id
<
FBGraphUser
>)user
{

NSString
*greetingText =
@"Greetings"
;

NSString
*userName = user.
first_name
;


self
.
greetingLabel
.
text
=
[
NSString

stringWithFormat
:
@"%@ %@"
, greetingText, userName];

self
.
profilePictureView
.
profileID
= user.
id
;
}
-(
void
)loginViewShowingLoggedOutUser:(
FBLoginView
*)loginView
{

self
.
greetingLabel
.
text
=
@"Login for a special greeting"
;

self
.
profilePictureView
.
profileID
=
nil
;
}
!
Add two lines of code to viewDidLoad
"
Implement the FBLoginViewDelegate
Friday, April 19, 13
Facebook Login Dialogs
Good
Built-in to iOS!+
Better
Leverages latest version of
the installed Facebook app
More informative
Friday, April 19, 13
Demo: FBLoginView
Friday, April 19, 13
Best Practices for Using Facebook Login

Use the latest SDKs for native login

Augment your own authentication
mechanism

Separate read and write permissions

Ask for write permissions in context

Explain why you need Facebook Login
Friday, April 19, 13
The Empty Room Problem
The Empty Room Problem

Where are my friends?

Where is the art and
decor I love?

What is there to do that I
will like?
Friday, April 19, 13
LISTEN
READ
RUN
COOK
Like
Like
Like
Like
The Social Graph
Friday, April 19, 13
https://graph.facebook.com
API for people, things, and the connections between them

/me
- get profile information for the currently logged-in user

/me/friends -
get a list of that person’s friends

/me?fields=endoapp:run
- get all that person’s runs on Endomondo

/[place_id]
- get information about places where your users are

/search?q=[term]&type=[post/checkin/place]
- search for public updates on a topic
call /me maybe?
Friday, April 19, 13
Extended
Profile
Properties
Email
Privacy & Permissions: Reading Data
Public
Profile
id, name, first_name, last_name, link, username, gender, locale
email
user_about_me, user_activities, user_birthday,
user_checkins, user_education_history, user_events,
user_groups, user_hometown, user_interests,
user_likes, user_location, user_notes, user_questions,
user_relationships, user_relationship_details,
user_religion_politics, user_status,
user_subscriptions, user_videos, user_website,
user_work_history, user_actions.music,
user_actions.news, user_actions.video,
user_games_activity, user_actions:APP_NAMESPACE
read_friendlists, read_insights, read_mailbox,
read_requests, read_stream, xmpp_login, ads_management,
create_event, manage_friendlists, manage_notifications,
user_online_presence, friends_online_presence,
publish_checkins, publish_actions, rsvp_event
Friday, April 19, 13
Privacy & Permissions: Be Responsible
Friday, April 19, 13
Using the Graph API Explorer
Friday, April 19, 13
// create the request to get /me
FBRequest
*me = [
FBRequest

requestForMe
];
// make the request and supply a block to be executed upon completion
[me
startWithCompletionHandler
:^(
FBRequestConnection
*connection,
id
<
FBGraphUser
> user,
NSError
*error) {

if
([user
objectForKey
:
@"languages"
]) {

NSArray
*languages = [user
objectForKey
:
@"languages"
];

for
(
int
i =
0
; i < [languages
count
]; i++) {

if
([[[languages
objectAtIndex
:i]
objectForKey
:
@"name"
]

isEqualToString
:
@"Klingon"
]) {

self
.
greetingLabel
.
text
=
@"Heghlu'meH QaQ jajvam!"
;
}
}
}
}];
Friday, April 19, 13
Demo: Using the Facebook Graph API
Friday, April 19, 13
Resources
http://developers.facebook.com/ios
Facebook SDK ".# for iOS
github.com/fbsamples
github.com/coolasspuppy
www.appdesignvault.com
Promo Code:
FB-$%&$' ($#( off)
Friday, April 19, 13
!"#
$%#
"$#
&'#
(##
$##%
$##)
$#!#
$#!!
$#!$
Footnote:
http://en.wikipedia.org/wiki/Google_Play, http://en.wikipedia.org/wiki/App_Store_(iOS)
Time
Available Apps (Thousands)
!"","""
Get Discovered
Friday, April 19, 13