-
Notifications
You must be signed in to change notification settings - Fork 1
Cloud Messaging
Before you can use the Firebase Cloud Messaging, you will need to create a Firebase project, and add the Firebase Unity SDK packages to your Unity project. To use the API, you must first configure your game in the Firebase console. Import Firebase Unity SDK to your project. You only need FirebaseMessaging.package. from the Firebase SDK.
Important: During the process, you must download a google-services.json file.
You can download this file again at any time.
The Firebase Cloud Message library will be initialized when adding handlers for either the TokenReceived or MessageReceived events.Upon initialization, a registration token is requested for the client app instance. The app will receive the token with the OnTokenReceived event, which should be cached for later use. You'll need this token if you want to target this specific device for messages.
The entire setup looks like this:
AN_FirebaseMessaging.Initialize((token) => {
m_tokenText.text = token;
AN_Logger.Log("FB Token: " + m_tokenText.text);
});
In addition, you will need to register for the OnMessageReceived event if you want to be able to receive incoming messages.
AN_FirebaseMessaging.OnFbMessageReceived.AddListener((message) => {
AN_Logger.Log("msg.CollapseKey " + message.CollapseKey);
AN_Logger.Log("msg.Error " + message.Error);
AN_Logger.Log("msg.ErrorDescription " + message.ErrorDescription);
AN_Logger.Log("msg.MessageId " + message.MessageId);
AN_Logger.Log("msg.MessageType " + message.MessageType);
AN_Logger.Log("msg.NotificationOpened " + message.NotificationOpened);
AN_Logger.Log("msg.Priority " + message.Priority);
AN_Logger.Log("msg.RawData " + message.RawData);
AN_Logger.Log("msg.TO " + message.To);
foreach (KeyValuePair<string, string> data in message.Data) {
AN_Logger.Log("data key: " + data.Key + " data value: " + data.Value);
}
AN_Logger.Log("msg.link " + message.Link);
AN_Logger.Log("msg.TimeToLive " + message.TimeToLive);
if (message.Notification == null)
return;
AN_Logger.Log("msg.Notification.Title " + message.Notification.Title);
AN_Logger.Log("msg.TitleLocalizationKey " + message.Notification.TitleLocalizationKey);
AN_Logger.Log("msg.Body " + message.Notification.Body);
m_messageText.text = message.Notification.Body;
});
Reliable and high-quality Unity Development service. Let's Talk!
Website | AssetStore | LinkedIn | Youtube | Scripting Reference
- Build Info
- Dark Mode
- Package Info
- Runtime Permissions
- Run External App
- Immersive Mode
- PackageManager
- Popups & Preloaders
- Rate Us Dialog
- Activity
- Intent
- Settings Page
- Media Player
- Date Picker Dialog
- Time Picker Dialog
- Locale
- Wheel Picker Dialog
- Developer Console Setup
- Connecting to The Service
- Purchase Flow
- Transactions Validation
- Subscriptions
- Licensing
- Getting Started
- Games Sing-in
- Server-side API Access
- Leaderboards
- Achievements
- Saved Games
- Image Manager
- Settings Intent