GUAPushResultObserver
[MSDK & Player Network SDK] Register the callback of the Push module, the game needs to process the callback function. For more information on the callback data structure, see GUAPushResult.
note
It is strongly recommended to perform registration in the startup function of the game application.
Function Definition
- Unity
- Unreal Engine
The list of methods used to process the callback events.
Callback Event | Common | [Player Network SDK Only] | [MSDK Only] |
---|---|---|---|
PushNotificationEvents | AddLocalNotification, ClearLocalNotification | - | - |
event OnResultHandler<GUAPushResult> PushNotificationEvents;
Callback Event | Common | [Player Network SDK Only] | [MSDK Only] |
---|---|---|---|
OnReceiveNotification | AddLocalNotification, ClearLocalNotification | - | - |
class GUA_EXTERN GUAPushObserver
{
public:
virtual ~GUAPushObserver() {};
virtual void OnReceiveNotification(const GUAPushResult &push_ret) {};
};
Code Sample
- Unity
- Unreal Engine
// Add callbacks
UnionAdapterAPI.GetPushService().PushNotificationEvents += OnPushNotificationEvent;
// Remove callbacks
UnionAdapterAPI.GetPushService().PushNotificationEvents -= OnPushNotificationEvent;
// PushNotificationEvents callback
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 handling (v1.15 +)
// 1. Define an observer class that inherits from GUA_NAMESPACE::GUAPushObserver at the engine level.
// 2. Implement a callback interface with the same method name such as OnReceiveNotification
class FGUAPushObserver : public GUA_NAMESPACE::GUAPushObserver {
public:
static FGUAPushObserver Instance;
void OnReceiveNotification(const GUA_NAMESPACE::GUAPushResult &push_ret)
{
}
};
FGUAPushObserver FGUAPushObserver::Instance;
//Configure the callback
GUA_NAMESPACE::GUAPushService::SetPushObserver(&FGUAPushObserver::Instance);