-
Notifications
You must be signed in to change notification settings - Fork 16
G.3 First Message
After initializing the FCM and retriving the token, follow the steps below to send your first notification message:
- Install and run the app on the target device.
- Make sure the app is in background mode or killed.
- Open the Notifications tab of the Firebase console and select New Message.
- Enter the message text.
- Select Single Device for the message target.
- In the field labeled FCM Registration Token, enter the registration token you obtained in a previous section of this guide.
After you click Send Message, targeted client devices will receive the notification in the system notifications tray.
NOTICE: There are generally two types of messages, data messages and notification messages. Please read the information on this page carefully to understand the difference between these FCM messages. These information has been customized for AIR developers. However if you wish to read the original documentation about the concept of FCM messages, check here: https://firebase.google.com/docs/cloud-messaging/concept-options
When your app is in foreground, you can listen to FcmEvents.MESSAGE
to know when a notification is received. If you are sending a notification message from your Firebase console, you still can set key/value pairs of custom payload data.
FCM.listener.addEventListener(FcmEvents.MESSAGE, onMessage);
function onMessage(e:FcmEvents):void
{
trace(e.msg)
var payload:Object = FCM.parsePayloadFromString(e.msg);
if (payload)
{
for (var name:String in payload)
{
trace(name + " = " + payload[name]);
}
}
}
NOTICE: Firebase console (currently) sends notification messages only. If you wish to send data messages, you need to perform a POST to the following URL https://fcm.googleapis.com/fcm/send
including the below headers:
Key: Content-Type, Value: application/json
Key: Authorization, Value: key=<your-server-key>
{
"data":
{
"key": "value"
},
"priority": "high",
"registration_ids":
[
"your-device-token",
"your-device2-token",
"your-device3-token",
".........."
]
}
HINT: You can find your server key in the firebase console: Your project, settings, Project settings, Cloud messaging, Server Key.
To learn more about how you should send notifications using your own server, you need to refer to Firebase original FCM documents. You may also find the information on this issue helpful.
Moreover, we have written a very helpful post about how you can build your own FCM console for sending out FCM messages. You can find the article here.
When your app is closed/in background, an FCM message will result in creating a notification. When you click on the notification, your app opens and you can listen to InvokeEvent.INVOKE
event to read the payload data that your message may include.
NativeApplication.nativeApplication.addEventListener(InvokeEvent.INVOKE, onInvoke);
function onInvoke(e:InvokeEvent):void
{
var payload:Object = FCM.parsePayloadFromArguments(e.arguments);
if (payload) // If available, it means that the Invoke listener contains FCM data
{
for (var name:String in payload)
{
trace(name + " = " + payload[name]);
}
}
}
Enjoy building Air apps – With ♥ from MyFlashLabs Team
Introduction to Firebase ANEs collection for Adobe Air apps
Get Started with Firebase Core in AIR
- Prerequisites
- Add Firebase to your app
- Add the Firebase SDK
- Init Firebase Core
- Available ANEs
- Managing Firebase iid
Get Started with Authentication
- Add Authentication
- Init Authentication
- Manage Users
- Phone Number
- Custom Auth
- Anonymous Auth
- State in Email Actions
- Email Link Authentication
Get Started with FCM + OneSignal
- Add FCM ANE
- Init FCM ANE
- Send Your 1st Message
- Send Msg to Topics
- Understanding FCM Messages
- init OneSignal
- Add Firestore
- Init Firestore
- Add Data
- Transactions & Batches
- Delete Data
- Manage the Console
- Get Data
- Get Realtime Updates
- Simple and Compound
- Order and Limit Data
- Paginate Data
- Manage Indexes
- Secure Data
- Offline Data
- Where to Go From Here
Get Started with Realtime Database
- Add Realtime Database
- Init Realtime Database
- Structure Your Database
- Save Data
- Retrieve Data
- Enable Offline Capabilities
Get Started with Remote Config
- Add Storage ANE
- Init Storage ANE
- Upload Files to Storage
- Download Files to Air
- Use File Metadata
- Delete Files