Packagecom.myflashlab.air.extensions.firebase.fcm
Classpublic class FCM
InheritanceFCM Inheritance 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/



Public Properties
 PropertyDefined 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
Public Methods
 MethodDefined 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
  
[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
Public Constants
 ConstantDefined By
  EXTENSION_ID : String = com.myflashlab.air.extensions.firebase.fcm
[static]
FCM
  VERSION : String = 9.9.0
[static]
FCM
Property Detail
autoInitEnabledproperty
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.


Implementation
    public static function get autoInitEnabled():Boolean
    public static function set autoInitEnabled(value:Boolean):void
listenerproperty 
listener:EventDispatcher  [read-only]


Implementation
    public static function get listener():EventDispatcher
Method Detail
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


Example
To receive the FCM token, you must pass in a callback function with two parameters.
         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():String

Deprecated, use getInstanceId method instead.

Returns
String
init()method 
public static function init():void

Call 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

Returns
Object

See also


Example
The following example will show you how you can parse FCM data in the INVOKE event
         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

Returns
Object

See also


Example
The following example will show you how you can parse FCM data in the INVOKE event
         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):void

Subscribe 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):void

Unsubscribe 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}".

Constant Detail
EXTENSION_IDConstant
public static const EXTENSION_ID:String = com.myflashlab.air.extensions.firebase.fcm

VERSIONConstant 
public static const VERSION:String = 9.9.0