Chuyển tới nội dung chính

Unity Push Notifications

Setup​

  • Android: FCM, from google-services.json under Assets (see Installation). Nothing else.
  • iOS: tick Enable iOS Push Notifications on the AlogameSDKSettings asset once the App ID has Push enabled in the Apple Developer portal. The build hook adds the Push capability (aps-environment), the remote-notification background mode, and the Unity flag that passes the APNs token to the SDK. It is off by default because the entitlement fails signing with a provisioning profile that has no push.

Ask for permission​

Ask when it suits the game:

C#
bool granted = await AlogamePush.RequestPermission();

The SDK registers the device token with the backend, before and after login, and shows Alogame's pushes itself.

Receive messages​

C#
AlogamePush.MessageReceived += data =>
{
if (data.TryGetValue("title", out var title)) Debug.Log($"push: {title}");
};
AlogamePush.TokenRefreshed += token => Debug.Log("push token rotated");

Optional​

CallAndroidiOS
AlogamePush.GetDeviceToken()FCM tokenAPNs token (hex), after permission is granted
AlogamePush.SubscribeToTopic(topic) / UnsubscribeFromTopic(topic)FCM topicsrejected (no APNs equivalent)