Retrieve Synchronous Notifications
Last updated on
To retrieve a synchronous notification using the SDK, you need to add the notification delegate.
- Unreal Engine
- Unity
const auto NotificationDelegate = AccelByte::Api::Lobby::FMessageNotif::CreateLambda([](const FAccelByteModelsNotificationMessage& Result)
{
UE_LOG(LogTemp, Log, TEXT("There is an incoming notification."));
UE_LOG(LogTemp, Log, TEXT("From: %s \nTo: %s\nTopic: %s"), *Result.From, *Result.To, *Result.Topic);
UE_LOG(LogTemp, Log, TEXT("Notification: %s"), *Result.Payload);
});
AccelByte::FRegistry::Lobby.SetMessageNotifDelegate(NotificationDelegate);
AccelByte::FRegistry::Lobby.Connect();
public static void OnReceiveNotification(Result<Notification> result)
{
Debug.Log(result.IsError);
Debug.Log("There is an incoming notification.");
Debug.Log(result.Value.payload);
}
public static void Main(string[] args)
{
var lobby = AccelBytePlugin.GetLobby();
lobby.OnNotification += OnReceiveNotification;
lobby.Connect();
}
You can also filter notifications by topic.
- Unreal Engine
- Unity
const auto NotificationDelegate = AccelByte::Api::Lobby::FMessageNotif::CreateLambda([](const FAccelByteModelsNotificationMessage& Result)
{
UE_LOG(LogTemp, Log, TEXT("There is an incoming notification."));
if(Result.Topic == "INGAME")
{
UE_LOG(LogTemp, Log, TEXT("Game notification: %s"), *result.Payload);
}
Else if(Result.Topic == "EVENT")
{
UE_LOG(LogTemp, Log, TEXT("Event notification: %s"), *result.Payload);
}
});
public static void OnReceiveNotification(Result<Notification> result)
{
Debug.Log(result.IsError);
Debug.Log("There is an incoming notification.");
switch(result.Value.topic){
case "INGAME" : Debug.Log("Game notification: " + result.Value.payload); break;
case "EVENT" : Debug.Log("Event notification: " + result.Value.payload); break;
}
}