This feature has been deprecated.
With Custom Update, you can send a custom message in a Messenger conversation between the people who are playing. This is a popular feature by Instant Game, and now available across platforms with Cross Play.
We added three APIs to the iOS SDK to access the context ID. These APIs will trigger a dialog for user to interact with and return a context token ID, which you will need to make custom update.
Create Context API is used to let two players play together for the first time. To call the Create Context API, you need the player ID of player which the current player wishes to play with, who needs be a Facebook friend of the current logged-in user. You can retrieve the playerID using the following graphAPI Endpoint:
GET /{user-id}/friends
Once retrieved the PlayerID, you can build a CreateContextContent object and trigger the dialog:
let createContextContent = CreateContextContent(playerID: "playerID")
try ContextDialogPresenter().makeAndShowCreateContextDialog(
content: createContextContent,
delegate: delegate
)
Swtich Context API is used to swtich into a context that is created earlier. To call the Create Context API, you need the context Token ID.
After user's confirmation on the dialog, the Facebook SDK update with the current context token identifier it saves in its state.
let switchContextContent = SwitchContextContent(contextID: "contextID")
try ContextDialogPresenter().makeAndShowCreateContextDialog(
content: switchContextContent,
delegate: delegate
)
The context Choose dialog is works differently than the switch and create. This dialog performs an app switch if the Facebook app is installed on the device. If the Facebook app is not installed we switch into safari browser and display the m-site version of context choose dialog.
To call this API, you need to create a ChooseContextContent object. ChooseContextContent holds the required data such as Filter, Min and Max Participants to show the dialog.
let chooseContextContent = ChooseContextContent()
chooseContextContent.filter = .newPlayersOnly
chooseContextContent.minParticipants = 1;
chooseContextContent.maxParticipants = 2;
ContextDialogPresenter().makeAndShowChooseContextDialog(
content: chooseContextContent,
delegate: delegate
)
ContextDialogDelegate: The delegate that will be triggered when dialog Cancels, Fails or Completes. While the dialogs return the current context when invoked, it is best to use the GamingContext helper class to keep track of the current context. This will allow you to know what context the player is in even if they join a session from messenger.
func contextDialogDidComplete(_ contextDialog: ContextWebDialog) {
//Dialog succeed check GamingContext.Current for current context
}
func contextDialog(_ contextDialog: ContextWebDialog, didFailWithError error: Error) {
//Dialog failed with error
}
func contextDialogDidCancel(_ contextDialog: ContextWebDialog) {
//Dialog cancelled
}
// Getting current context
GamingContext.Current
When contextDialogDidComplete is invoked,that means the context create, switch, or choose dialog completed succesfully. You should check the gaming context for the current context identifier and perform a custom update.
When contextDialogDidCancel is invoked, this either means the user returned to the game without interacting with the dialog or they cancelled on the dialog without completing. At this point it’s up to you to prompt the user to retry or wait for a later time.
When contextDialog:didFailWithError is invoked it means the dialog encountered some sort of error while attempting to show the dialog or during the user’s interaction with the dialog. You will receive the dialog that encountered an error and the error, to handle the next steps.
Custom updates allows you to send a messenger attachment to the players in the current context to let them know of an in-game event. This is done via the following Graph API.
POST /me/custom_update
To make calling this API easier we provide a high level wrapper in the SDK which will allow you to use strong data types.
// Using customUpdateContentMedia with a url representing a gif will be displayed
CustomUpdateGraphRequest().request(content: customUpdateContentMedia, completionHandler: completion)
// Using customUpdateContentImage with a UIimage that a bitmap will be displayed
CustomUpdateGraphRequest().request(content: customUpdateContentImage, completionHandler: completion)
The graph request will return a success value to indicate whether the custom update was successfully sent.