Package | com.distriqt.extension.pushnotifications |
Class | public class PushNotifications |
Inheritance | PushNotifications ![]() |
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
Property | Defined 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 |
Method | Defined By | ||
---|---|---|---|
Class Constructor
| PushNotifications | ||
authorisationStatus():String
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 | ||
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:
"device token" with APNS;
"registration id" with Android GCM;
"instance token" with FCM.
The value unique identifies this device. | PushNotifications | ||
getServiceToken():String | PushNotifications | ||
getTags():Boolean
Retrieve a list of tags that have been set on the user from the service. | PushNotifications | ||
hasAuthorisation():Boolean
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 | ||
openDeviceSettings():Boolean
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 | ||
removeUserId():void
Allows you to disassociate a custom user identifier from your application with
the notification service identifier. | PushNotifications | ||
requestAuthorisation():Boolean
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 | ||
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 |
Event | Summary | Defined By | ||
---|---|---|---|---|
Dispatched when the authorisation status may have changed | PushNotifications | |||
This event is dispatched when the user clicks on a notification action | PushNotifications | |||
An error has occurred | PushNotifications | |||
This event is dispatched when the user clicks on a group notification | PushNotifications | |||
A Notification was received | PushNotifications | |||
This event is dispatched when the user clicks on a notification | PushNotifications | |||
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 fails | PushNotifications | |||
Dispatched on successful registration with the server | PushNotifications | |||
This event is dispatched when the service is attempting to register | PushNotifications | |||
Dispatched when the service has unregistered from the server | PushNotifications |
Constant | Defined By | ||
---|---|---|---|
EXT_CONTEXT_ID : String = com.distriqt.PushNotifications [static] | PushNotifications | ||
VERSION : String = 16.0.2 [static] | PushNotifications |
canOpenDeviceSettings | property |
canOpenDeviceSettings:Boolean
[read-only]
Returns true if you can display the device settings for your application.
public function get canOpenDeviceSettings():Boolean
canSendTags | property |
canSendTags:Boolean
[read-only] Returns whether the current service supports the setting of tags on the current user registration.
public function get canSendTags():Boolean
canSubscribeToTopics | property |
canSubscribeToTopics:Boolean
[read-only]
Returns true
if the current service supports topic subscription
and false
otherwise.
public function get canSubscribeToTopics():Boolean
implementation | property |
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:
Android
iOS
default
unknown
public function get implementation():String
inAppMessaging | property |
inAppMessaging:InAppMessaging
[read-only]
public function get inAppMessaging():InAppMessaging
isSupported | property |
isSupported:Boolean
[read-only] Whether the platform supports push notifications
public static function get isSupported():Boolean
nativeVersion | property |
nativeVersion:String
[read-only]
The native version string of the native extension.
public function get nativeVersion():String
service | property |
service:PushNotifications
[read-only] The singleton instance of the PushNotifications class.
public static function get service():PushNotifications
version | property |
version:String
[read-only]
The version of this extension.
This should be of the format, MAJOR.MINOR.BUILD
public function get version():String
PushNotifications | () | Constructor |
public function PushNotifications()
Class Constructor
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.
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
|
Boolean — true 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.
|
Boolean — true 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.
ReturnsString |
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.
ReturnsBoolean — true 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.
ReturnsBoolean — true if notifications can be displayed and false otherwise.
|
init | () | method |
public static function init(key:String):void
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
|
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.
ReturnsBoolean — true 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:Boolean — true if your user has granted permission
|
Boolean — true 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.
ReturnsBoolean — 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
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.
|
Boolean — true 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.
|
Boolean — true 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
|
Boolean |
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
|
Boolean — true 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
|
Boolean — true if successful
|
authorisation:changed | Event |
com.distriqt.extension.pushnotifications.events.AuthorisationEvent
com.distriqt.extension.pushnotifications.events.AuthorisationEvent.CHANGED
Dispatched when the authorisation status may have changed
pushnotification:action | Event |
com.distriqt.extension.pushnotifications.events.PushNotificationEvent
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 |
com.distriqt.extension.pushnotifications.events.PushNotificationEvent
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 |
com.distriqt.extension.pushnotifications.events.PushNotificationGroupEvent
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 |
com.distriqt.extension.pushnotifications.events.PushNotificationEvent
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 |
com.distriqt.extension.pushnotifications.events.PushNotificationEvent
com.distriqt.extension.pushnotifications.events.PushNotificationEvent.NOTIFICATON_SELECTED
This event is dispatched when the user clicks on a notification
registration:error | Event |
com.distriqt.extension.pushnotifications.events.RegistrationEvent
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 |
com.distriqt.extension.pushnotifications.events.RegistrationEvent
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 |
com.distriqt.extension.pushnotifications.events.RegistrationEvent
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 |
com.distriqt.extension.pushnotifications.events.RegistrationEvent
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 |
com.distriqt.extension.pushnotifications.events.RegistrationEvent
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
EXT_CONTEXT_ID | Constant |
public static const EXT_CONTEXT_ID:String = com.distriqt.PushNotifications
VERSION | Constant |
public static const VERSION:String = 16.0.2