Skip to main content

Overview

GameRequestDialog lets users invite or challenge Facebook friends from within your game. You configure a GameRequestContent object describing the request and present the dialog. The SDK handles both web-based and native (Gaming Services deep link) presentation automatically. Module: FacebookGamingServices
Declared in: GameRequestDialog.swift
Objective-C name: FBSDKGameRequestDialog

Initializer

init(content:delegate:)

public init(content: GameRequestContent, delegate: GameRequestDialogDelegate?)
content
GameRequestContent
The content describing the game request. See GameRequestContent below.
delegate
GameRequestDialogDelegate?
A weak delegate that receives completion, failure, and cancellation callbacks.

Static factory methods

GameRequestDialog.dialog(content:delegate:)

Creates but does not show a GameRequestDialog.
@objc(dialogWithContent:delegate:)
public static func dialog(
    content: GameRequestContent,
    delegate: GameRequestDialogDelegate?
) -> GameRequestDialog

GameRequestDialog.show(content:delegate:)

Creates and immediately shows a GameRequestDialog.
@discardableResult
@objc(showWithContent:delegate:)
public static func show(
    content: GameRequestContent,
    delegate: GameRequestDialogDelegate?
) -> GameRequestDialog

Properties

content
GameRequestContent
The game request content. You can update this before calling show().
delegate
GameRequestDialogDelegate?
The delegate receiving dialog events. Weak reference.
isFrictionlessRequestsEnabled
Bool
When true, requests to friends who have previously accepted frictionless requests are sent without showing the dialog. Defaults to false.
canShow
Bool
Always returns true for GameRequestDialog. Use validate() to check content validity before showing.

Methods

show()

Presents the game request dialog.
@discardableResult
public func show() -> Bool
return value
Bool
true if the dialog was presented, false if validation failed.

validate()

Validates the content on the receiver. Throws if the content is invalid.
public func validate() throws

GameRequestContent

GameRequestContent describes the request to send. Objective-C name: FBSDKGameRequestContent

Properties

message
String
The plain-text message to send as part of the request. Required. Defaults to an empty string.
actionType
GameRequestActionType
Additional context about the nature of the request. Defaults to .none. When set to .send or .askFor, you must also provide a non-empty objectID.
filters
GameRequestFilter
Controls which friends appear in the multi-friend selector. Defaults to .none (all friends). Cannot be combined with recipients or recipientSuggestions.
recipients
[String]
An array of user IDs, usernames, or invite tokens specifying the target recipients. When set, the sender cannot choose recipients. Cannot be combined with filters or recipientSuggestions.
recipientSuggestions
[String]
User IDs to pre-populate as suggested friends in the multi-friend selector. Cannot be combined with recipients or filters.
data
String?
Freeform data stored with the request object, up to 255 characters. Use this to pass game-specific state.
title
String
The title shown in the game request dialog. Defaults to an empty string.
objectID
String
The Open Graph object ID for .send and .askFor action types. Defaults to an empty string.
cta
String
The call-to-action text shown in the dialog. Defaults to an empty string.

GameRequestActionType enum

CaseDescription
.noneNo specific action type (default).
.sendThe user is sending an in-game object to friends. Requires objectID.
.askForThe user is requesting an in-game object from friends. Requires objectID.
.turnNotifies friends that it is their turn in a match.
.inviteThe user is inviting a friend to the game.

GameRequestFilter enum

CaseDescription
.noneAll friends can be shown in the selector (default).
.appUsersOnly friends who already use the app are shown.
.appNonUsersOnly friends who do not use the app are shown.
.everybodyAll friends are shown when the Facebook app is installed.

GameRequestDialogDelegate protocol

Objective-C name: FBSDKGameRequestDialogDelegate

gameRequestDialog(_:didCompleteWithResults:)

Called when the request is sent successfully.
func gameRequestDialog(
    _ gameRequestDialog: GameRequestDialog,
    didCompleteWithResults results: [String: Any]
)
results
[String: Any]
A dictionary containing the request ID and recipients. Keys include request_id and recipients.

gameRequestDialog(_:didFailWithError:)

Called when the dialog encounters an error.
func gameRequestDialog(
    _ gameRequestDialog: GameRequestDialog,
    didFailWithError error: Error
)

gameRequestDialogDidCancel(_:)

Called when the user dismisses the dialog without sending a request.
func gameRequestDialogDidCancel(_ gameRequestDialog: GameRequestDialog)

Usage example

import FacebookGamingServices

class GameRequestViewController: UIViewController, GameRequestDialogDelegate {

    func sendInvite() {
        let content = GameRequestContent()
        content.message = "Join me in this game!"
        content.title = "Play with me"
        content.actionType = .invite

        let dialog = GameRequestDialog(content: content, delegate: self)
        dialog.show()
    }

    func sendItem(objectID: String, to friends: [String]) {
        let content = GameRequestContent()
        content.message = "I'm sending you a power-up!"
        content.actionType = .send
        content.objectID = objectID
        content.recipients = friends

        GameRequestDialog.show(content: content, delegate: self)
    }

    // MARK: - GameRequestDialogDelegate

    func gameRequestDialog(
        _ gameRequestDialog: GameRequestDialog,
        didCompleteWithResults results: [String: Any]
    ) {
        print("Request sent. ID:", results["request_id"] ?? "")
    }

    func gameRequestDialog(
        _ gameRequestDialog: GameRequestDialog,
        didFailWithError error: Error
    ) {
        print("Request failed:", error)
    }

    func gameRequestDialogDidCancel(_ gameRequestDialog: GameRequestDialog) {
        print("Request cancelled")
    }
}

Build docs developers (and LLMs) love