The SDK for tvOS provides an easy way to implement Facebook Login For Devices.
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.
Smart Login was introduced with v4.17.0 of the Facebook SDK for tvOS and makes the login experience even easier by communicating the code directly to the Facebook app on the same wireless network. No API changes are needed to take advantage of this feature.
#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 *viewController = [[FBSDKDeviceLoginViewController alloc] init]; viewController.publishPermissions = @[@"email"]; viewController.delegate = self; [self presentViewController:viewController animated:YES completion:NULL];
To log a user out, simply clear the current access token:
You can also redirect the user to your app's website after completing the authorization by setting the
redirectURL property of the button or view controller. This is especially useful if you have additional account management for the person.
button.redirectURL = ...;