-
Notifications
You must be signed in to change notification settings - Fork 16
G.5 Send Messages to Topics
Based on the publish/subscribe model, FCM topic messaging allows you to send a message to multiple devices that have opted in to a particular topic. You compose topic messages as needed, and Firebase handles routing and delivering the message reliably to the right devices.
For example, users of a local weather forecasting app could opt in to a "severe weather alerts" topic and receive notifications of storms threatening specified areas. Users of a sports app could subscribe to automatic updates in live game scores for their favorite teams.
Some things to keep in mind about topics:
- Topic messaging supports unlimited subscriptions for each app.
- Topic messaging is best suited for content such as news, weather, or other publicly available information.
- Topic messages are optimized for throughput rather than latency. For fast, secure delivery to single devices or small groups of devices, target messages to tokens, not topics.
- If you need to send messages to multiple devices per user, consider Device Group messaging for those use cases.
Client apps can subscribe to any existing topic, or they can create a new topic. When a client app subscribes to a new topic name (one that does not already exist for your Firebase project), a new topic of that name is created in FCM and any client can subsequently subscribe to it.
FCM.listener.addEventListener(FcmEvents.ON_SUBSCRIBE, onSubscribeResult);
// It will take 24 hours before you can see this topic on the Firebase console
FCM.subscribeToTopic("news");
private function onSubscribeResult(e:FcmEvents):void
{
trace("subscribe to topic " + e.topic + ": " + e.isSuccessful);
}
To unsubscribe, the client app calls Firebase Cloud Messaging unsubscribeFromTopic() with the topic name.
FCM.listener.addEventListener(FcmEvents.ON_UNSUBSCRIBE, onUnsubscribeResult);
FCM.unsubscribeFromTopic("news");
private function onUnsubscribeResult(e:FcmEvents):void
{
trace("unsubscribe to topic " + e.topic + ": " + e.isSuccessful);
}
NOTICE: When a new topic is created, you will not see that topic in your Firebase console sooner than 24 hours! If you need to check the availability of the newly created topic, you need to send a GET request to https://iid.googleapis.com/iid/info/TOKEN_ID?details=true
replacing the TOKEN_ID
with the String you received from the FCM.getToken()
method. While calling the above request, you need to send the following header also:
Authorization: key=<your-server-key>
content-type: application/json
HINT: You can find your server key in the firebase console: Your project, settings, Project settings, Cloud messaging, Server Key.
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