Facebook SDK for tvOS

The new Apple TV brings the App Store to the big screen at home. With the Facebook SDK for tvOS you can build great social experiences on Apple TV.

With the Facebook SDK for tvOS, you can integrate the following features into your tvOS app:

  • Facebook Login - Fast and easy way for people to log into your tvOS app and so you can provide rich, personalized experiences. People will be able to use their account created on their mobile device.
  • Share to Facebook - Make it easy for people to share links, photos and videos from your tvOS app with their friends on Facebook.
  • Facebook Analytics for Apps - Build better experiences by understanding your audience and how people engage with your tvOS app.

To make Facebook Login quick and easy, people simply enter a confirmation code displayed on the TV into their smartphone or computer - rather than entering their username and password with the remote.

Download the SDK for tvOS

Frameworks

In the same way that the Apple tvOS SDK inherits iOS frameworks, the Facebook SDK for tvOS inherits from the Facebook SDK for iOS. Here are the available Facebook frameworks for tvOS.

FBSDKLoginKit.framework

This framework is unavailable for tvOS. Use the new FBSDKTVOSKit.framework instead.

FBSDKCoreKit.framework (modified)

The following classes are available:

  • FBSDKAccessToken
  • FBSDKAppEvents
  • FBSDKApplicationDelegate
  • FBSDKGraphRequest
  • FBSDKGraphRequestConnection
  • FBSDKSettings

FBSDKShareKit.framework (modified)

The following classes are available:

  • FBSDKShareAPI
  • FBSDKShareConstants
  • FBSDKShareLinkContent
  • FBSDKShareOpenGraphAction
  • FBSDKShareOpenGraphContent
  • FBSDKShareOpenGraphObject
  • FBSDKSharePhoto
  • FBSDKSharePhotoContent
  • FBSDKShareVideo
  • FBSDKShareVideoContent
  • FBSDKSharing
  • FBSDKSharingContent

FBSDKTVOSKit.framework (new)

  • FBSDKDeviceLoginButton
  • FBSDKDeviceLoginViewController

Getting Started

Download the Facebook SDK for tvOS.

Getting started with the Facebook SDK for tvOS is exactly the same as Getting Started with the Facebook SDK for iOS.

Swift

You can import the Facebook frameworks as modules directly (e.g., import FBSDKCoreKit) after linking them to your project.

Login

Login with Facebook is easy with the new TVOSKit.framework. Simply add the FBSDKDeviceLoginButton button to your view.

When a person focuses and selects the button, a modal dialog slides into the view and present a confirmation code. Once someone confirms the code, the button notifies its delegate and the [FBSDKAccessToken currentAccessToken] will be set.

To enable this feature, go to your app settings (https://developers.facebook.com/apps/{YOUR_APP_ID}/settings/advanced/) - Advanced - Client Oauth Settings and turn on Login from Devices:

Example:

#import <FBSDKTVOSKit/FBSDKTVOSKit.h>

FBSDKDeviceLoginButton *button = [[FBSDKDeviceLoginButton alloc] initWithFrame:CGRectZero];
button.readPermissions = @[@"email"]; //optional.
button.center = self.view.center;
[self.view addSubview:button];

If you need to provide specific reauthorization behavior, for example if you are asking for additional permissions, you can directly present the modal dialog by showing an instance of FBSDKDeviceLoginViewController

Example:

FBSDKDeviceLoginViewController *viewController = [[FBSDKDeviceLoginViewController alloc] init];
viewController.publishPermissions = @[@"publish_actions"];
viewController.delegate = self;
[self presentViewController:viewController animated:YES completion:NULL];

To log a user out, simply clear the current access token:

[FBSDKAccessToken setCurrentAccessToken:nil];

Sharing

Your app can share content through the FBSDKShareAPI class with an authorized access token. To create shared content, follow the same approach used for SDK for iOS. See the section on Custom Interfaces in the Sharing documentation. The sharing dialogs are not available on tvOS.

Example:

#import <FBSDKShareKit/FBSDKShareKit.h>


FBSDKShareLinkContent *linkContent = [[FBSDKShareLinkContent alloc] init];
linkContent.contentURL = [NSURL URLWithString:@"http://developers.facebook.com/docs/tvos"];
[FBSDKShareAPI shareWithContent:linkContent delegate:self];

Analytics

You add rich analytics to your tvOS apps by logging events in the same way as the Facebook SDK for iOS. Login is not required for your app to log events.

Example:

#import <FBSDKCoreKit/FBSDKCoreKit.h>



[FBSDKAppEvents activateApp];

Graph API

You can also access the social graph in the same way as our SDK for iOS, see Using the Graph API, iOS. To do this you need an access token with the right permissions from the person using your app.

Example:

#import <FBSDKCoreKit/FBSDKCoreKit.h>


// If you have user_likes permission granted
FBSDKGraphRequest *request = [[FBSDKGraphRequest alloc] initWithGraphPath:@"me/likes" parameters:nil];
[request startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) {
  //TODO: process error or result.
}];

For more information on user permissions, see Permissions with Facebook Login.