Push module callback (GUAPushResultObserver)
[MSDK & Player Network SDK] Register the callback for the Push module. The game needs to register the callback for processing.For more about the callback data structure, see GUABaseResult.
note
It is strongly recommended that games register in the application startup function.
Function Definition
- Unity
- Unreal Engine
Method list for handling callback events
| Callback event | Common | [Player Network SDK only] | [MSD only] |
|---|---|---|---|
| PushNotificationEvents | AddLocalNotification, ClearLocalNotification | * | - |
event OnResultHandler<GUAPushResult> PushNotificationEvents;
| Callback event | Common | [Player Network SDK only] | [MSD only] |
|---|---|---|---|
| OnReceiveNotification | AddLocalNotification, ClearLocalNotification | * | - |
class GUA_EXTERN GUAPushObserver
{
public:
virtual ~GUAPushObserver() {};
virtual void OnReceiveNotification(const GUAPushResult &push_ret) {};
};
Code Example
- Unity
- Unreal Engine
// Add callback
UnionAdapterAPI.GetPushService().PushNotificationEvents += OnPushNotificationEvent;
// Remove callback
UnionAdapterAPI.GetPushService().PushNotificationEvents -= OnPushNotificationEvent;
// Callback handling for PushNotificationEvents
private void OnPushNotificationEvent(GUAPushResult pushResult)
{
string methodTag = "";
if (pushResult.MethodId == (int)GUAMethodID.GUA_PUSH_ADD_LOCAL_NOTIFICATION)
{
methodTag = "AddLocalNotification";
}
else if (pushResult.MethodId == (int)GUAMethodID.GUA_PUSH_CLEAR_LOCAL_NOTIFICATIONS)
{
methodTag = "ClearLocalNotification";
}
else if (pushResult.MethodId == (int)GUAMethodID.GUA_PUSH_NOTIFICATION_CALLBACK)
{
methodTag = "NotificationCallback";
}
Debug.Log(methodTag + pushResult.ToString());
}
C++ Event Handling - Callback (v1.15 and above)
// 1. In the engine layer, define an observer class that inherits from GUA_NAMESPACE::GUAPushObserver
// 2. Implement the callback interface with the same method names (e.g., OnReceiveNotification)
class FGUAPushObserver : public GUA_NAMESPACE::GUAPushObserver {
public:
static FGUAPushObserver Instance;
void OnReceiveNotification(const GUA_NAMESPACE::GUAPushResult &push_ret)
{
}
};
FGUAPushObserver FGUAPushObserver::Instance;
// Set the callback
GUA_NAMESPACE::GUAPushService::SetPushObserver(&FGUAPushObserver::Instance);