| Package | com.myflashlab.air.extensions.firebase.fcm |
| Class | public class FCM |
| Inheritance | FCM Object |
Firebase Cloud Messaging enables apps to communicate with their app servers using simple messages.
Messages can be sent from the Firebase Notifications console, using a topic that has been subscribed to via
subscribeToTopic(String), or by getting a token for an app instance via getInstanceId().
The current version of this ANE is not supporting custom notifications via downstream or upstream. You can send notifications ONLY through the Firebase Console. We are working on improving this child ANE to support other features like the native side. make sure you are subscribed to our newsletter so you can be notified as soon as the new features are released: https://www.myflashlabs.com/contact/
| Property | Defined By | ||
|---|---|---|---|
| autoInitEnabled : Boolean [static]
Is Firebase Messaging token auto generation enabled? If this flag is disabled,
Firebase Messaging will not generate token automatically for message delivery. | FCM | ||
| listener : EventDispatcher [static] [read-only] | FCM | ||
| Method | Defined By | ||
|---|---|---|---|
getInstanceId($callback:Function):void [static]
Returns the ID and automatically generated token for this Firebase project. | FCM | ||
getToken():String [static]
Deprecated, use getInstanceId method instead. | FCM | ||
init():void [static]
Call this method prior to any other FCM methods. | FCM | ||
parsePayloadFromArguments($arguments:Array):Object [static]
Helpful optional method to parse raw FCM data from server to an Object containing key/value pairs of the custom
payload data that the FCM might contain. | FCM | ||
parsePayloadFromString($str:String):Object [static]
Helpful optional method to parse raw FCM data from server to an Object containing key/value pairs of the custom
payload data that the FCM might contain. | FCM | ||
registerChannel($channel:NotificationChannel):void [static]
(Android) Notification channels are needed on Android 8+ only. | FCM | ||
subscribeToTopic($topic:String):void [static]
Subscribe to topic in background. | FCM | ||
unsubscribeFromTopic($topic:String):void [static]
Unsubscribe from topic in background. | FCM | ||
| Constant | Defined By | ||
|---|---|---|---|
| EXTENSION_ID : String = com.myflashlab.air.extensions.firebase.fcm [static] | FCM | ||
| VERSION : String = 9.9.0 [static] | FCM | ||
| autoInitEnabled | property |
autoInitEnabled:Boolean
Is Firebase Messaging token auto generation enabled? If this flag is disabled, Firebase Messaging will not generate token automatically for message delivery.
If this flag is disabled, Firebase Messaging does not generate new tokens automatically for message delivery. If this flag is enabled, FCM generates a registration token on application start when there is no existing valid token. FCM also generates a new token when an existing token is deleted.
This setting is persisted, and is applied on future invocations of your application. Once explicitly set, it overrides any settings in your manifest .xml file.
By default, FCM automatic initialization is enabled.
public static function get autoInitEnabled():Boolean public static function set autoInitEnabled(value:Boolean):void| listener | property |
listener:EventDispatcher [read-only] public static function get listener():EventDispatcher| getInstanceId | () | method |
public static function getInstanceId($callback:Function):void
Returns the ID and automatically generated token for this Firebase project. This generates an Instance ID if
it does not exist yet. This method is identical to Firebase.iid.getInstanceId on the native
side. But for ease of use for AIR devs, we have it here also.
Parameters
$callback:Function |
FCM.getInstanceId(onTokenReceived);
function onTokenReceived($token:String, $error:String):void
{
if($error)
{
trace("onTokenReceived error: " + $error);
}
if($token)
{
trace("token: " + $token);
}
}
| getToken | () | method |
public static function getToken():StringDeprecated, use getInstanceId method instead.
ReturnsString |
| init | () | method |
public static function init():voidCall this method prior to any other FCM methods.
| parsePayloadFromArguments | () | method |
public static function parsePayloadFromArguments($arguments:Array):Object
Helpful optional method to parse raw FCM data from server to an Object containing key/value pairs of the custom payload data that the FCM might contain. If you're not posting any custom payload key/values with your FCM, then this method won't be necessary.
When you receive an FCM notification while your app is closed, a notification will be generated. When this
notification is clicked, your app will open and you will receive the FCM payload data in
InvokeEvent.INVOKE event.
Parameters
$arguments:Array |
Object —
|
See also
private 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]);
}
}
}
| parsePayloadFromString | () | method |
public static function parsePayloadFromString($str:String):Object
Helpful optional method to parse raw FCM data from server to an Object containing key/value pairs of the custom payload data that the FCM might contain. If you're not posting any custom payload key/values with your FCM, then this method won't be necessary.
When you receive an FCM notification while your app is running, the FcmEvents.MESSAGE event
will be dispatched, you can extract the key/value pairs of custom payload data using this method.
Parameters
$str:String |
Object —
|
See also
private 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]);
}
}
}
| registerChannel | () | method |
public static function registerChannel($channel:NotificationChannel):void(Android) Notification channels are needed on Android 8+ only. You need to create one or more channels for notifications in your app and then pass the channel instance when posting the FCM message.
Parameters
$channel:NotificationChannel |
| subscribeToTopic | () | method |
public static function subscribeToTopic($topic:String):voidSubscribe to topic in background.
Parameters
$topic:String — The name of the topic to subscribe. Must match the following regular expression: "[a-zA-Z0-9-_.~%]{1,900}".
|
| unsubscribeFromTopic | () | method |
public static function unsubscribeFromTopic($topic:String):voidUnsubscribe from topic in background.
Parameters
$topic:String — The name of the topic to unsubscribe from. Must match the following regular expression: "[a-zA-Z0-9-_.~%]{1,900}".
|
| EXTENSION_ID | Constant |
public static const EXTENSION_ID:String = com.myflashlab.air.extensions.firebase.fcm| VERSION | Constant |
public static const VERSION:String = 9.9.0