15. Push notifications
Who does what
A push notification needs two things: a device token for each phone, and a sender allowed to send to those tokens. Google's Firebase Cloud Messaging (FCM) provides both for Android and iPhones. So push runs through your game's own Firebase project, and the work splits like this:
| You | MultiConnectCloud |
|---|---|
| Create a Firebase project for the game (or use the one you have) | — |
| Give MultiConnectCloud permission to send through that project: one key file (Step 1) | Keeps the key encrypted and uses it only to send your game's pushes |
| For iPhones, give Firebase Apple's push key, in Firebase itself (Step 2) | — |
| Add Firebase Messaging to the game, and hand each device's token to MultiConnectSDK (Step 3) | Stores each player's tokens, and removes tokens Firebase reports as dead |
| Decide what to send: from the dashboard or from your game server (Step 4) | Sends to the right players' devices, at the right time, and shows what was sent |
Step 1: Let MultiConnectCloud send through your Firebase project
Why: Firebase only accepts a push from a sender that proves it is allowed to use your project. That proof is a service account key: a .json file Firebase creates. MultiConnectCloud signs each send with it. It's the only file the Push notifications page asks for, and the same key sends to Android phones and iPhones.
How to get it:
- Open the Firebase console and choose your game's project. If you don't have one, choose Create a project.
- Open ⚙ Project settings → Service accounts and choose Generate new private key, then Generate key. A
.jsonfile downloads. Keep it private: anyone with it can send pushes to your players.
Where it goes: open your app on SDK Apps → Push notifications. Under Firebase, choose Choose the key file, pick the .json file, then Save and test. The card then shows Project and your project's id.
How it's used: only to send your game's pushes. It's stored encrypted and never shown again. Remove on the same card deletes it, and pushes stop.
Step 2 (iPhones only): give Firebase Apple's push key
Why: Apple delivers every notification to an iPhone itself, through its Apple Push Notification service (APNs). Firebase passes your iPhone pushes to APNs, and Apple accepts them only with your APNs key. This key goes to Firebase, not to MultiConnectCloud: nothing about it is entered on the dashboard. An Android-only game skips this step.
How to get it and where it goes:
- In Apple Developer → Keys, choose +, name it (e.g.
Game push), tick Apple Push Notifications service (APNs), then Continue and Register. - Choose Download to get
AuthKey_….p8. Apple lets you download it only once. Note the Key ID on that page, and your Team ID (top right of the developer site, or under Membership). - In the Firebase console, add your iOS app if the project doesn't have it: Add app → iOS, with your app's bundle id.
- Open ⚙ Project settings → Cloud Messaging → Apple app configuration, choose your iOS app, and under APNs Authentication Key choose Upload: the
.p8file, the Key ID and the Team ID.
One APNs key covers development and production builds, and every app on your Apple team.
Step 3: Add Firebase Messaging to the game
Why: a device token can only come from Firebase Messaging running on the device: Android and iOS hand it out to the app, through Firebase, and nothing else can get it. MultiConnectSDK doesn't include Firebase; your game adds it, then passes the token to MultiConnectSDK, which links it to the signed-in player.
Set up the Unity project once:
- Download the Firebase Unity SDK and import
FirebaseMessaging.unitypackage(Assets → Import Package → Custom Package). If the game already uses another Firebase package, such as Crashlytics, use the same Firebase version. - In the Firebase console, ⚙ Project settings → Your apps, download each app's config file and put it anywhere under
Assets:google-services.jsonfor Android (add an Android app with your package name first if there isn't one);GoogleService-Info.plistfor iOS.
- Android: choose Assets → External Dependency Manager → Android Resolver → Resolve.
- iOS: after building the Xcode project, check that Signing & Capabilities has Push Notifications, and Background Modes with Remote notifications ticked.
Then the script. Firebase can hand over a token before the player has signed in, but a token can only be registered for a signed-in player. Script 15.1 keeps the token and registers it once both are there, and again when either changes.
Script 15.1: Get the token from Firebase and register it
using Firebase;
using Firebase.Messaging;
using MultiConnect.App;
using UnityEngine;
/// <summary>Gets this device's push token from Firebase and registers it for the signed-in player.</summary>
public class PushSetup : MonoBehaviour
{
private string _token = "";
private async void Start()
{
var status = await FirebaseApp.CheckAndFixDependenciesAsync();
if (status != DependencyStatus.Available)
{
Debug.LogWarning("Firebase is not available: " + status);
return;
}
FirebaseMessaging.TokenReceived += (_, e) => { _token = e.Token; Register(); };
FirebaseMessaging.MessageReceived += (_, e) =>
{
// A push arrived or was tapped while the game runs. "screen" is the dashboard's Open screen field.
if (e.Message.Data.TryGetValue("screen", out var screen)) Debug.Log("Open screen: " + screen);
};
McApp.PlayerChanged += _ => Register(); // sign-in and account switch
await FirebaseMessaging.RequestPermissionAsync(); // the notification prompt on iOS and Android 13+
}
private async void Register()
{
if (_token.Length == 0 || !McApp.IsSignedIn) return; // runs again when the other half arrives
var result = await McAppPush.RegisterAsync(_token);
if (!result.Ok) Debug.Log("Push token not registered: " + result.Message);
}
}
Put Script 15.1 on an object in your first scene, next to the boot script (Script 3.1).
Check it worked: on a real phone (pushes don't reach the Unity Editor, and the iOS Simulator is unreliable), start the game and sign in. The device count at the top of the Push notifications page goes up by one.
If your settings let a player turn notifications off, call McAppPush.UnregisterAsync(token). Turning them back on registers again.
Step 4: Send
From the dashboard: New push, at the top right of the Push notifications page, sends a notification yourself: an event starting, a sale, an update. It's available once the Firebase key is saved. Set:
- the Title and Text;
- optionally a screen to open (Open screen (optional data: screen)), which reaches your game as the data key
screen(Script 15.1); - who gets it: Player ids (empty = everyone), Platforms (none = all), From version, and Played in last N days (0 = any);
- Send at, UTC (empty = now). The page shows the same moment in your own time zone under it.
From your server, for something only the game knows, such as "it's your turn":
Script 15.2: Server: send a push
using System.Collections.Generic;
using System.Threading.Tasks;
using MultiConnect.App;
public static class TurnReminder
{
public static Task Send(string playerId, string opponentName) =>
McAppServer.SendPushAsync(new[] { playerId }, "Your turn", opponentName + " has played.",
new Dictionary<string, string> { { "screen", "game" } });
}
An inbox message can also go out as a push (section 12). Sent and scheduled on the Push notifications page lists every push, whoever sent it, with how many devices it reached; a scheduled one can be cancelled there before it goes.

