推送模块的回调(GUAPushResultObserver)
[MSDK & Player Network SDK] 注册 Push 模块的回调,游戏需要注册回调函数进行处理。更多关于回调数据结构,可以查看 GUABaseResult。
注意
强烈建议游戏在应用启动函数中进行注册。
函数定义
- Unity
- Unreal Engine
回调事件用于处理的方法列表
回调事件 | Common | [仅限 Player Network SDK] | [仅限 MSD] |
---|---|---|---|
PushNotificationEvents | AddLocalNotification, ClearLocalNotification | - | - |
event OnResultHandler<GUAPushResult> PushNotificationEvents;
回调事件 | Common | [仅限 Player Network SDK] | [仅限 MSD] |
---|---|---|---|
OnReceiveNotification | AddLocalNotification, ClearLocalNotification | - | - |
class GUA_EXTERN GUAPushObserver
{
public:
virtual ~GUAPushObserver() {};
virtual void OnReceiveNotification(const GUAPushResult &push_ret) {};
};
代码示例
- Unity
- Unreal Engine
// 增加回调
UnionAdapterAPI.GetPushService().PushNotificationEvents += OnPushNotificationEvent;
// 移除回调
UnionAdapterAPI.GetPushService().PushNotificationEvents -= OnPushNotificationEvent;
// 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++ 事件处理 - 回调处理 (v1.15 以上)
// 1.在引擎层定义继承自 GUA_NAMESPACE::GUAPushObserver 的观察者类
// 2.实现方法名一样的回调接口(如:OnReceiveNotification)
class FGUAPushObserver : public GUA_NAMESPACE::GUAPushObserver {
public:
static FGUAPushObserver Instance;
void OnReceiveNotification(const GUA_NAMESPACE::GUAPushResult &push_ret)
{
}
};
FGUAPushObserver FGUAPushObserver::Instance;
// 设置回调
GUA_NAMESPACE::GUAPushService::SetPushObserver(&FGUAPushObserver::Instance);