Packagecom.distriqt.extension.pushnotifications
Classpublic class PushNotifications
InheritancePushNotifications Inheritance flash.events.EventDispatcher

This class is the Push Notifications Native Extension interface. It implements the different push notifications services on the supported platforms giving the developer one consistent interface to push notifications across these platforms.

The currently implemented platforms are listed in the documentation, but include:

For information on using this extension visit the getting started guide: here



Public Properties
 PropertyDefined By
  canOpenDeviceSettings : Boolean
[read-only] Returns true if you can display the device settings for your application.
PushNotifications
  canSendTags : Boolean
[read-only] Returns whether the current service supports the setting of tags on the current user registration.
PushNotifications
  canSubscribeToTopics : Boolean
[read-only] Returns true if the current service supports topic subscription and false otherwise.
PushNotifications
  implementation : String
[read-only] The implementation currently in use.
PushNotifications
  inAppMessaging : InAppMessaging
[read-only]
PushNotifications
  isSupported : Boolean
[static] [read-only] Whether the platform supports push notifications
PushNotifications
  nativeVersion : String
[read-only] The native version string of the native extension.
PushNotifications
  service : PushNotifications
[static] [read-only] The singleton instance of the PushNotifications class.
PushNotifications
  version : String
[read-only] The version of this extension.
PushNotifications
Public Methods
 MethodDefined By
  
Class Constructor
PushNotifications
  
Returns the current authorisation status of the device.
PushNotifications
  
cancelAll():void
Cancels any notifications currently displayed.
PushNotifications
  
deleteTag(tag:String):Boolean
Deletes a single tag that was previously set on a user with sendTag or sendTags.
PushNotifications
  
deleteTags(tags:Array):Boolean
Deletes one or more tags that were previously set on a user with sendTag or sendTags.
PushNotifications
  
dispose():void
Disposes the extension and releases any allocated resources.
PushNotifications
  
Returns the deviceToken or registration ID value of a currently registered device from the notification service This value has slightly different terminology on each of the services, as below: "device token" with APNS; "registration id" with Android GCM; "instance token" with FCM. The value unique identifies this device.
PushNotifications
  
PushNotifications
  
getTags():Boolean
Retrieve a list of tags that have been set on the user from the service.
PushNotifications
  
If true the user has granted authorisation to display notifications on this device.
PushNotifications
  
init(key:String):void
Deprecated: You no longer need to use an application key
[static] Initialises the extension class for use with the provided key.
PushNotifications
  
isServiceSupported(serviceType:String):Boolean
Checks if the specified service type is supported on the current device.
PushNotifications
  
iOS 8 introduced the ability to send your user to your application's device settings within the iOS Settings.
PushNotifications
  
provideUserConsent(granted:Boolean):Boolean
If your Service is set to require the user's privacy consent and the service supports this functionality, you can provide this consent using this method.
PushNotifications
  
register():Boolean
Registers this device with the push notification service.
PushNotifications
  
Allows you to disassociate a custom user identifier from your application with the notification service identifier.
PushNotifications
  
This function triggers the authorisation request dialog.
PushNotifications
  
sendTag(key:String, value:String):Boolean
Tag a user based on an app event/property of your choosing to target these users.
PushNotifications
  
sendTags(tags:Object):Boolean
Tag a user based on an app event/property of your choosing to target these users.
PushNotifications
  
setBadgeNumber(number:int):void
Sets the badge number for the application icon Support: iOS Android: Limited, see documentation
PushNotifications
  
setup(service:Service):Boolean
Sets up the service configuration
PushNotifications
  
setUserId(userId:String, authHash:String):void
This allows you to associate a custom identifier with your user.
PushNotifications
  
subscribeToTopic(topic:String):Boolean
Subscribe the current client to the specified topic
PushNotifications
  
unregister():void
Unregisters the current device
PushNotifications
  
unsubscribeFromTopic(topic:String):Boolean
Unsubscribe the current client from the specified topic
PushNotifications
Events
 Event Summary Defined By
   Dispatched when the authorisation status may have changed PushNotifications
  This event is dispatched when the user clicks on a notification actionPushNotifications
  An error has occurredPushNotifications
  This event is dispatched when the user clicks on a group notificationPushNotifications
  A Notification was receivedPushNotifications
  This event is dispatched when the user clicks on a notificationPushNotifications
   An error has occurred The data field will contain more information about the error that occurred Android additional errors: SERVICE_NOT_AVAILABLE: The device can't read the response, or there was a 500/503 from the server that can be retried later.PushNotifications
  Dispatched when the registration process failsPushNotifications
  Dispatched on successful registration with the serverPushNotifications
  This event is dispatched when the service is attempting to registerPushNotifications
  Dispatched when the service has unregistered from the serverPushNotifications
Public Constants
 ConstantDefined By
  EXT_CONTEXT_ID : String = com.distriqt.PushNotifications
[static]
PushNotifications
  VERSION : String = 16.0.2
[static]
PushNotifications
Property Detail
canOpenDeviceSettingsproperty
canOpenDeviceSettings:Boolean  [read-only]

Returns true if you can display the device settings for your application.


Implementation
    public function get canOpenDeviceSettings():Boolean
canSendTagsproperty 
canSendTags:Boolean  [read-only]

Returns whether the current service supports the setting of tags on the current user registration.


Implementation
    public function get canSendTags():Boolean
canSubscribeToTopicsproperty 
canSubscribeToTopics:Boolean  [read-only]

Returns true if the current service supports topic subscription and false otherwise.


Implementation
    public function get canSubscribeToTopics():Boolean
implementationproperty 
implementation:String  [read-only]

The implementation currently in use. This should be one of the following depending on the platform in use and the functionality supported by this extension:


Implementation
    public function get implementation():String
inAppMessagingproperty 
inAppMessaging:InAppMessaging  [read-only]


Implementation
    public function get inAppMessaging():InAppMessaging
isSupportedproperty 
isSupported:Boolean  [read-only]

Whether the platform supports push notifications


Implementation
    public static function get isSupported():Boolean
nativeVersionproperty 
nativeVersion:String  [read-only]

The native version string of the native extension.


Implementation
    public function get nativeVersion():String
serviceproperty 
service:PushNotifications  [read-only]

The singleton instance of the PushNotifications class.


Implementation
    public static function get service():PushNotifications
versionproperty 
version:String  [read-only]

The version of this extension.

This should be of the format, MAJOR.MINOR.BUILD


Implementation
    public function get version():String
Constructor Detail
PushNotifications()Constructor
public function PushNotifications()

Class Constructor

Method Detail
authorisationStatus()method
public function authorisationStatus():String

Returns the current authorisation status of the device. This status indicates whether the user has authorised or denied access to notifications.

The NOT_DETERMINED status is returned when your application is first installed and you have not yet requested authorisation.

Returns
String — A value from the AuthorisationStatus constants
cancelAll()method 
public function cancelAll():void

Cancels any notifications currently displayed.

This may cancel local notifications as well created via the Notifications extension.

Support: Android, iOS

deleteTag()method 
public function deleteTag(tag:String):Boolean

Deletes a single tag that was previously set on a user with sendTag or sendTags. Use deleteTags if you need to delete more than one.

Parameters

tag:String — Key of the tag to delete

Returns
Booleantrue if successfully started and false if not supported or there was an error
deleteTags()method 
public function deleteTags(tags:Array):Boolean

Deletes one or more tags that were previously set on a user with sendTag or sendTags.

Parameters

tags:Array — Array of string keys for the tags to delete.

Returns
Booleantrue if successfully started and false if not supported or there was an error
dispose()method 
public function dispose():void

Disposes the extension and releases any allocated resources. Once this function has been called, a call to init is neccesary again before any of the extensions functionality will work.

getDeviceToken()method 
public function getDeviceToken():String

Returns the deviceToken or registration ID value of a currently registered device from the notification service

This value has slightly different terminology on each of the services, as below:

The value unique identifies this device. It may change and you should be prepared to manage changing tokens on your server.

Returns
String
getServiceToken()method 
public function getServiceToken():String

Returns
String
getTags()method 
public function getTags():Boolean

Retrieve a list of tags that have been set on the user from the service.

Returns
Booleantrue if successfully started and false if not supported or there was an error
hasAuthorisation()method 
public function hasAuthorisation():Boolean

If true the user has granted authorisation to display notifications on this device.

This will also return false if authorisation has not yet been requested.

Returns
Boolean — true if notifications can be displayed and false otherwise.
init()method 
public static function init(key:String):void
Deprecated: You no longer need to use an application key

Initialises the extension class for use with the provided key.

Parameters

key:String

isServiceSupported()method 
public function isServiceSupported(serviceType:String):Boolean

Checks if the specified service type is supported on the current device.

Parameters

serviceType:String — The type of service to check

Returns
Boolean — true if the service is supported and false otherwise
openDeviceSettings()method 
public function openDeviceSettings():Boolean

iOS 8 introduced the ability to send your user to your application's device settings within the iOS Settings.

Returns
Booleantrue if the settings open was successful and false if the device settings are not available.
provideUserConsent()method 
public function provideUserConsent(granted:Boolean):Boolean

If your Service is set to require the user's privacy consent and the service supports this functionality, you can provide this consent using this method. Until you call provideUserConsent(true), the service will not fully initialize and will not send any data to the service.

Parameters

granted:Booleantrue if your user has granted permission

Returns
Booleantrue if successful and false if not supported or there was an error

See also

register()method 
public function register():Boolean

Registers this device with the push notification service. You must have called setup before calling this function.

You should make sure you have added all the event listeners for notifications you require before calling this function since any startup events will fire immediately after a call to this function.

On iOS this will present the request push notifications permission dialog the first time you request it. You should read this guide on the right way to ask users for permissions.

Returns
Boolean — true if the registration was attempted and false if the service is still initialising

See also

removeUserId()method 
public function removeUserId():void

Allows you to disassociate a custom user identifier from your application with the notification service identifier. You should call this if your user logs out of your application. Only supported on OneSignal currently (equivalent to removeExternalUserId)

requestAuthorisation()method 
public function requestAuthorisation():Boolean

This function triggers the authorisation request dialog. This dialog will only be displayed once to a user on iOS so make sure you have adequately informed your user why you are requesting authorisation.

Note calling register at any point will trigger the request authorisation dialog as well so make sure you have implemented your authorisation logic before calling register

Returns
Boolean — true if the request was started successfully and false otherwise
sendTag()method 
public function sendTag(key:String, value:String):Boolean

Tag a user based on an app event/property of your choosing to target these users. Use sendTags if you need to set more than one tag on a user at a time.

Parameters

key:String — Key of your choosing to create or update.
 
value:String — Value to set on the key. NOTE: Passing in a blank/empty string deletes the key, you can also call deleteTag or deleteTags.

Returns
Booleantrue if successfully started and false if not supported or there was an error
sendTags()method 
public function sendTags(tags:Object):Boolean

Tag a user based on an app event/property of your choosing to target these users.

Parameters

tags:Object — Key value pairs of your choosing. These should be string values and keys.

Returns
Booleantrue if successfully started and false if not supported or there was an error
setBadgeNumber()method 
public function setBadgeNumber(number:int):void

Sets the badge number for the application icon

Support:

Parameters

number:int — Badge number to set

setup()method 
public function setup(service:Service):Boolean

Sets up the service configuration

Parameters

service:Service — The service configuration

Returns
Boolean

Example
An example of setting up the default service with a single category
         var service:Service = new Service( Service.DEFAULT, Config.gcmSenderId );
         service.enableNotificationsWhenActive = true;
         service.categories.push(
             new CategoryBuilder()
                 .setIdentifier( "INVITE_CATEGORY" )
                 .addAction( 
                     new ActionBuilder()
                         .setTitle( "Accept" )
                         .setIdentifier( "ACCEPT_IDENTIFIER" )
                         .build()
                 )
                 .addAction( 
                     new ActionBuilder()    
                         .setTitle( "Delete" )
                         .setDestructive( true )
                         .setIdentifier( "DELETE_IDENTIFIER" )
                         .build()
                 )
                 .build()
         );
         
         PushNotifications.service.setup( service );
         
setUserId()method 
public function setUserId(userId:String, authHash:String):void

This allows you to associate a custom identifier with your user. You should call this method each time your user logs into your app to pass in your custom User ID (as a string). Only supported on OneSignal currently (equivalent to setExternalUserId)

Parameters

userId:String — The custom user identifier
 
authHash:String — [optional] auth hash (if required)

subscribeToTopic()method 
public function subscribeToTopic(topic:String):Boolean

Subscribe the current client to the specified topic

Parameters

topic:String — The topic to subscribe the client to

Returns
Booleantrue if successful
unregister()method 
public function unregister():void

Unregisters the current device

unsubscribeFromTopic()method 
public function unsubscribeFromTopic(topic:String):Boolean

Unsubscribe the current client from the specified topic

Parameters

topic:String — The topic to unsubscribe the client from

Returns
Booleantrue if successful
Event Detail
authorisation:changed Event
Event Object Type: com.distriqt.extension.pushnotifications.events.AuthorisationEvent
AuthorisationEvent.type property = com.distriqt.extension.pushnotifications.events.AuthorisationEvent.CHANGED

Dispatched when the authorisation status may have changed

pushnotification:action Event  
Event Object Type: com.distriqt.extension.pushnotifications.events.PushNotificationEvent
PushNotificationEvent.type property = com.distriqt.extension.pushnotifications.events.PushNotificationEvent.ACTION

This event is dispatched when the user clicks on a notification action

Dispatched when a user selects an action on a notification.

The identifier will contain the identifier of the action allowing you to determine what action to take.

pushnotification:error Event  
Event Object Type: com.distriqt.extension.pushnotifications.events.PushNotificationEvent
PushNotificationEvent.type property = com.distriqt.extension.pushnotifications.events.PushNotificationEvent.ERROR

An error has occurred

Dispatched when an error occurred, either an invalid format notification payload or a connection issue.

The payload will contain the details of the error.

pushnotification:group:selected Event  
Event Object Type: com.distriqt.extension.pushnotifications.events.PushNotificationGroupEvent
PushNotificationGroupEvent.type property = com.distriqt.extension.pushnotifications.events.PushNotificationGroupEvent.GROUP_SELECTED

This event is dispatched when the user clicks on a group notification

Dispatched when a group notification is selected

Android only

pushnotification:notification Event  
Event Object Type: com.distriqt.extension.pushnotifications.events.PushNotificationEvent
PushNotificationEvent.type property = com.distriqt.extension.pushnotifications.events.PushNotificationEvent.NOTIFICATION

A Notification was received

A Notification was received

The payload field will contain a json formatted string containing the payload sent with this notification.

pushnotification:notification:selected Event  
Event Object Type: com.distriqt.extension.pushnotifications.events.PushNotificationEvent
PushNotificationEvent.type property = com.distriqt.extension.pushnotifications.events.PushNotificationEvent.NOTIFICATON_SELECTED

This event is dispatched when the user clicks on a notification

registration:error Event  
Event Object Type: com.distriqt.extension.pushnotifications.events.RegistrationEvent
RegistrationEvent.type property = com.distriqt.extension.pushnotifications.events.RegistrationEvent.ERROR

An error has occurred

The data field will contain more information about the error that occurred

Android additional errors:

iOS additional errors:

registration:register:failed Event  
Event Object Type: com.distriqt.extension.pushnotifications.events.RegistrationEvent
RegistrationEvent.type property = com.distriqt.extension.pushnotifications.events.RegistrationEvent.REGISTER_FAILED

Dispatched when the registration process fails

Dispatched when the registration process fails. This could be due to connection issues or an issue with the server at the time of connection.

registration:register:success Event  
Event Object Type: com.distriqt.extension.pushnotifications.events.RegistrationEvent
RegistrationEvent.type property = com.distriqt.extension.pushnotifications.events.RegistrationEvent.REGISTER_SUCCESS

Dispatched on successful registration with the server

Dispatched on successful registration with the server

The call to getDeviceToken will now return a valid registration id.

registration:registering Event  
Event Object Type: com.distriqt.extension.pushnotifications.events.RegistrationEvent
RegistrationEvent.type property = com.distriqt.extension.pushnotifications.events.RegistrationEvent.REGISTERING

This event is dispatched when the service is attempting to register

This event is dispatched when the service is attempting to register

registration:unregistered Event  
Event Object Type: com.distriqt.extension.pushnotifications.events.RegistrationEvent
RegistrationEvent.type property = com.distriqt.extension.pushnotifications.events.RegistrationEvent.UNREGISTERED

Dispatched when the service has unregistered from the server

Android only

Dispatched when the service has unregistered from the server

Constant Detail
EXT_CONTEXT_IDConstant
public static const EXT_CONTEXT_ID:String = com.distriqt.PushNotifications

VERSIONConstant 
public static const VERSION:String = 16.0.2