Gaming Services iOS SDK

Facebook 로그인, Facebook 공유 또는 Facebook Gaming을 통합하고 나서 특정 앱 이벤트가 이벤트 관리자에 대해 자동으로 로깅 및 수집됩니다. 단, 자동 앱 이벤트 로깅을 비활성화하는 경우는 예외입니다. Facebook 로그인, Facebook 공유 또는 Facebook Gaming을 사용하는 모든 개발자 여러분께서는 이 기능의 작동 방법을 숙지하시기 바랍니다. 수집되는 정보 및 자동 앱 이벤트 로깅을 비활성화하는 방법에 대한 자세한 내용은 자동 앱 이벤트 로깅을 참조하세요.

Gaming Services is available as a new component in the official Facebook SDK for iOS. Using Facebook official SDKs is the recommended approach and makes it easy to access services enabled by Facebook Login for Gaming including the Player Finder and Sharing (for Gaming) experiences.

Prerequisites

  1. Your application needs to enroll in Gaming Services to access features in this document. Follow the instructions to enroll your application.
  2. Make sure you have the minimal version of Facebook iOS SDK or above. Download the latest version.
  3. Ensure your App settings are properly configured for app switch.

Implementation

Facebook Login for Gaming

Facebook Login for Gaming enables a new login method for games. It supports the same implementation and SDK methods as Facebook Login. If this is the first time you're integrating the Facebook SDK into your App, refer to the configuration guide before proceeding.

Instead of receiving public_profile, your application will receive gaming_profile as the default permission. Other requestable permissions include user_friends, email, and gaming_user_picture.


Gaming Graph Domain

After integrating with Facebook Login for Gaming, your application will receive an access token for use on Gaming graph domain (graph.fb.gg), instead of the Facebook graph domain (graph.facebook.com). Read more about gaming graph domain.

You can check if the current User has connected with Facebook Login For Gaming by verifying the Graph Domain to be gaming in the Access Token:

// (c) Facebook, Inc. and its affiliates. Confidential and proprietary.
...
#import <FBSDKCoreKit/FBSDKCoreKit.h>
...
if ([[FBSDKAccessToken currentAccessToken].graphDomain isEqualToString:@"gaming"]) {
  // current user has been migrated to Facebook Login for Gaming
}

Player Finder and Sharing for Gaming

Here's an example from our sample App, which shows how to invoke the Player Finder and Sharing dialogs through the iOS SDK. It also shows the response you can expect from each of them.

// (c) Facebook, Inc. and its affiliates. Confidential and proprietary.

#import "GamingServicesCellController.h"

#import <MobileCoreServices/MobileCoreServices.h>
#import <UIKit/UIKit.h>

#import <FBSDKCoreKit/FBSDKCoreKit.h>
#import <FBSDKGamingServicesKit/FBSDKGamingServicesKit.h>
#import <FBSDKShareKit/FBSDKShareKit.h>

#import "Console.h"

static NSString *const kCellIdentifer = @"gaming-services-cell";

@interface MediaPickerDelegate : NSObject <UIImagePickerControllerDelegate, UINavigationControllerDelegate>
@property (nonatomic, copy) void (^callback)(id media);
@end

@implementation MediaPickerDelegate

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
  __weak typeof(self) weakSelf = self;
  [picker dismissViewControllerAnimated:true completion:^{
    weakSelf.callback(info[UIImagePickerControllerOriginalImage]
    ?: [info objectForKey:UIImagePickerControllerMediaURL]);
  }];
}

@end

static void UploadImage(UIImage *image)
{
  if (![image isKindOfClass:[UIImage class]]) {
    ConsoleError([NSError new], @"Bad Image passed to Image Upload");
    return;
  }

  FBSDKGamingImageUploaderConfiguration *config =
  [[FBSDKGamingImageUploaderConfiguration alloc]
   initWithImage:image
   caption:@"Cool Photo"
   shouldLaunchMediaDialog:YES];

  [FBSDKGamingImageUploader
   uploadImageWithConfiguration:config
   andCompletionHandler:^(BOOL success, NSError * _Nullable error) {
    if (!success || error) {
      ConsoleError(error, @"Failed to upload Image");
    } else {
      ConsoleSucceed(@"Image Upload Complete");
    }
  }];
}

static void UploadVideo(NSURL *videoURL)
{
  if (![videoURL isKindOfClass:[NSURL class]]) {
    ConsoleError([NSError new], @"Bad URL passed to Video Upload");
    return;
  }

  FBSDKGamingVideoUploaderConfiguration *config =
  [[FBSDKGamingVideoUploaderConfiguration alloc]
   initWithVideoURL:videoURL
   caption:@"Cool Video"];

  [FBSDKGamingVideoUploader
   uploadVideoWithConfiguration:config
   andCompletionHandler:^(BOOL success, NSError * _Nullable error) {
    if (!success || error) {
      ConsoleError(error, @"Failed to upload Video");
    } else {
      ConsoleSucceed(@"Video Upload Complete");
    }
  }];
}

static void LaunchMediaPicker(NSString *type)
{
  static MediaPickerDelegate *mediaDelegate;
  if (mediaDelegate == nil) {
    mediaDelegate = [MediaPickerDelegate new];
  }

  UIImagePickerController *const picker = [UIImagePickerController new];
  picker.delegate = mediaDelegate;
  picker.modalPresentationStyle = UIModalPresentationCurrentContext;

  if ([type isEqualToString:@"VIDEO"]) {
    picker.mediaTypes = @[(NSString*)kUTTypeMovie, (NSString*)kUTTypeAVIMovie, (NSString*)kUTTypeVideo, (NSString*)kUTTypeMPEG4];
    picker.videoQuality = UIImagePickerControllerQualityTypeHigh;
    mediaDelegate.callback = ^(id media) {
      UploadVideo(media);
    };
  } else {
    picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
    mediaDelegate.callback = ^(id media) {
      UploadImage(media);
    };
  }

  [[UIApplication sharedApplication].delegate.window.rootViewController
   presentViewController:picker
   animated:true
   completion:nil];
}

void GamingServicesRegisterCells(UITableView *tableView)
{
  [tableView
   registerClass:UITableViewCell.class
   forCellReuseIdentifier:kCellIdentifer];
}

UITableViewCell *GamingServicesConfiguredCell(NSIndexPath *indexPath, UITableView *tableView)
{
  UITableViewCell *const cell =
  [tableView
   dequeueReusableCellWithIdentifier:kCellIdentifer
   forIndexPath:indexPath];

  switch ((GamingServicesCellRow) indexPath.row) {
    case GamingServicesCellRowFriendFinder:
      cell.textLabel.text = @"Launch Player Finder";
      cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
      break;

    case GamingServicesCellRowUploadPhoto:
      cell.textLabel.text = @"Upload Photo";
      cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
      break;

    case GamingServicesCellRowUploadVideo:
      cell.textLabel.text = @"Upload Video";
      cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
      break;
  }

  return cell;
}

void GamingServicesDidSelectCell(GamingServicesCellRow row)
{
  switch (row) {
    case GamingServicesCellRowFriendFinder:
      [FBSDKFriendFinderDialog
       launchFriendFinderDialogWithCompletionHandler:^(BOOL success, NSError * _Nullable error) {
        if (!success || error) {
          ConsoleError(error, @"Failed to launch Player Finder");
        } else {
          ConsoleSucceed(@"Friend Finding Complete");
        }
      }];
      break;

    case GamingServicesCellRowUploadPhoto:
      LaunchMediaPicker(@"IMAGE");
      break;

    case GamingServicesCellRowUploadVideo:
      LaunchMediaPicker(@"VIDEO");
      break;
  }
}