Skip to main content
Game requests let your app send notifications to a user’s Facebook friends. You can use them to invite friends to play, ask for in-game items, signal that it’s someone’s turn, or send any custom message.

Build the content

Describe the request using GameRequestContent.
import FacebookGamingServices

let content = GameRequestContent()
content.message = "Come join me in Puzzle Quest!"
content.actionType = .invite

Properties

PropertyTypeRequiredDescription
messageStringYesPlain-text message displayed in the request notification.
actionTypeGameRequestActionTypeNoDescribes the nature of the request. Defaults to .none.
objectIDStringConditionalRequired when actionType is .send or .askFor.
recipients[String]NoUser IDs or invite tokens to send the request to directly. If set, the multi-friend selector is skipped.
recipientSuggestions[String]NoUser IDs to pre-populate as the first suggestions in the selector. Cannot be combined with recipients or filters.
filtersGameRequestFilterNoControls which friends appear in the multi-friend selector. Defaults to .none.
dataString?NoCustom tracking payload attached to the request. Maximum 255 characters.
titleStringNoTitle displayed at the top of the dialog.
ctaStringNoCall-to-action text for the dialog button.

Action types

ValueDescription
.noneNo specific action context.
.sendThe user is sending an object to friends. Requires objectID.
.askForThe user is requesting an object from friends. Requires objectID.
.turnIt is the friends’ turn to play in a match.
.inviteThe user is inviting a friend to the game.

Filter options

ValueDescription
.noneAll friends can be shown.
.appUsersOnly friends who already use the app.
.appNonUsersOnly friends who do not yet use the app.
.everybodyAll friends, when the Facebook app is installed.
You cannot combine recipients, recipientSuggestions, and filters in the same request. Setting more than one of these properties causes validation to fail when you call show().

Show the dialog

You can show the dialog in one step using the static convenience method:
GameRequestDialog.show(content: content, delegate: self)
Or create a dialog instance for more control:
let dialog = GameRequestDialog(content: content, delegate: self)
dialog.isFrictionlessRequestsEnabled = true
dialog.show()
Set isFrictionlessRequestsEnabled = true to skip the dialog for recipients who have previously accepted frictionless requests from your app.

Handle the result

Implement GameRequestDialogDelegate to receive outcomes.
extension GameViewController: GameRequestDialogDelegate {

    func gameRequestDialog(
        _ gameRequestDialog: GameRequestDialog,
        didCompleteWithResults results: [String: Any]
    ) {
        let requestID = results["request_id"] as? String ?? ""
        let recipients = results["recipients"] as? [String] ?? []
        print("Request \(requestID) sent to: \(recipients)")
    }

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

    func gameRequestDialogDidCancel(_ gameRequestDialog: GameRequestDialog) {
        print("User cancelled the game request")
    }
}
MethodWhen called
gameRequestDialog(_:didCompleteWithResults:)The request was sent. The results dictionary contains request_id and recipients.
gameRequestDialog(_:didFailWithError:)An error occurred.
gameRequestDialogDidCancel(_:)The user dismissed the dialog without sending.

Full example

import FacebookGamingServices

class GameViewController: UIViewController {

    func inviteFriendsToPlay() {
        let content = GameRequestContent()
        content.message = "It's your turn! Come play with me."
        content.actionType = .turn

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

extension GameViewController: GameRequestDialogDelegate {

    func gameRequestDialog(
        _ gameRequestDialog: GameRequestDialog,
        didCompleteWithResults results: [String: Any]
    ) {
        let requestID = results["request_id"] as? String ?? ""
        print("Request sent, ID: \(requestID)")
    }

    func gameRequestDialog(
        _ gameRequestDialog: GameRequestDialog,
        didFailWithError error: Error
    ) {
        print("Error: \(error.localizedDescription)")
    }

    func gameRequestDialogDidCancel(_ gameRequestDialog: GameRequestDialog) {}
}

Build docs developers (and LLMs) love