Modules.CloudPush
> Modules.CloudPush

Provides support for Android push notifications.

The CloudPush module supports Android push notifications for a device by providing a connection to the push notification server to the device to receive push notifications and to optionally present a tray notification to the user when a new push notification is received.

This module is only used to receive push notifications. For information on configuring your project to send push notifications, see Modules.Cloud.PushNotifications.

Push Protocols

As of Release 3.2.0, the CloudPush module only supports Google Cloud Messaging (GCM) for push notifications. MQTT support is deprecated and support was removed in Release 3.2.0. Upgrade your application to use the GCM protocol.

GCM supports devices that run Android 2.2 and later, and requires that the Google Play Store application be installed. For pre-4.0 devices, the user is required to set up their Google account.

Getting Started

To use the CloudPush module in your JavaScript code, you need to require it in and get a device token with the retrieveDeviceToken method to enable push notifications with Arrow Push. In your project's tiapp.xml, you need to add some keys to configure push notifications.

Note that this module is not included in the Titanium namespace, but it is bundled with the Titanium SDK as of version 2.0.0. To use it, you must require it, like this:

var CloudPush = require('ti.cloudpush');

Then, call the retrieveDeviceToken method to get a unique token specific to that device and Arrow DB application. This token is used with Arrow PushNotifications calls to subscribe and unsubscribe the device to push notification channels.

Once the device is subscribed to at least one push channel, listen to the module's callback, trayClickLaunchedApp, and trayClickFocusedApp events to monitor for incoming push notifications.

This module must also be added to the modules section in your tiapp.xml. This can be done using the Modules list in the Titanium Studio TiApp Editor, or by editing the XML directly and adding the following line to the modules element:

<module platform="android">ti.cloudpush</module>

Your app must prove that it is allowed to talk to Arrow. This keeps your data secure by preventing anyone from making requests to Arrow that impersonate your app.

Titanium Studio creates a pair of keys (Development and Production) for each Titanium application depending on the user preference specified during new project creation. This pair of keys will be stored in tiapp.xml and one of the keys will be used during application build depending on the build type (development or production).

To use push notifications, in the tiapp.xml file, you need to specify the Arrow Push keys and push type. The supported properties in tiapp.xml are:

<!-- Property keys for Arrow Push (required) -->
<property name="acs-api-key-development" type="string">YOUR DEVELOPMENT API KEY HERE</property>
<property name="acs-api-key-production" type="string">YOUR PRODUCTION API KEY HERE</property>
<property name="acs-api-key" type="string">YOUR API KEY HERE</property>

If a deployment-specific setting is provided (production or development) then that value will be used for the current deployment environment.

WARNING: The default properties of this module are used until you set a property for the first time. Because the properties are persisted to the device settings (via Titanium.App.Properties), the most recent value you set will always be used.

Virtual Private Cloud Configuration

If you are using a virtual private cloud (VPC), you need to configure your Arrow Push dispatcher URL in order to send push notifications with GCM. In the tiapp.xml file, add the acs-push-api-url application property and set the node text to the push dispatcher URL provided to you. The URL may be the same as your custom ArrowDB endpoint and have deployment-specific settings, that is, two URLs--one for production and another for the development environment.

<ti:app>
    <property name="acs-push-api-url-production">https://api-prod.fooinc.com</property>
    <property name="acs-push-api-url-development">https://api-dev.fooinc.com</property>
</ti:app>

Grouped Notifications

If the device receives multiple push notifications from the application, Android can group these notifications together as one notification.

To use grouped notifications, add a grouped notification template to either the tiapp.xml file or the i18n folder for internationalized versions:

tiapp.xml:

<property name="acs-grouped-notification-message-development" type="string">You have $number$ unread messages.</property>
<property name="acs-grouped-notification-message-production" type="string">You have $number$ unread messages.</property>
-or-
<property name="acs-grouped-notification-message" type="string">You have $number$ unread messages.</property>

i18n/es/strings.xml (example for Spanish):

<?xml version="1.0" encoding="utf-8"?>
<resources>
   <string name="acs_grouped_notification_message">Tienes $number$ mensajes no leidos.</string>
</resources>

The $number$ variable indicates the number of unread messages.

Examples

Listening for Push Notifications

This example lets the application retrieve the device token and listens for several events to monitor incoming push notifications.

var CloudPush = require('ti.cloudpush');
CloudPush.retrieveDeviceToken({
    success: function deviceTokenSuccess(e) {
        // Use this device token with Ti.Cloud.PushNotifications calls
        // to subscribe and unsubscribe to push notification channels
        Ti.API.info('Device Token: ' + e.deviceToken);
    },
    error: function deviceTokenError(e) {
        alert('Failed to register for push! ' + e.error);
    }
});
// These events monitor incoming push notifications
CloudPush.addEventListener('callback', function (evt) {
    alert(evt.payload);
});
CloudPush.addEventListener('trayClickLaunchedApp', function (evt) {
    Ti.API.info('Tray Click Launched App (app was not running)');
});
CloudPush.addEventListener('trayClickFocusedApp', function (evt) {
    Ti.API.info('Tray Click Focused App (app was already running)');
});
  • 2.0.0
Defined By

Properties

Modules.CloudPush
: Numberreadonly
Code returned from isGooglePlayServicesAvailable. ...

Code returned from isGooglePlayServicesAvailable. Google Play services has been disabled on this device.

  • 3.4.1
Modules.CloudPush
: Numberreadonly
Code returned from isGooglePlayServicesAvailable. ...

Code returned from isGooglePlayServicesAvailable. The version of Google Play services installed on this device is not authentic.

  • 3.4.1
Modules.CloudPush
: Numberreadonly
Code returned from isGooglePlayServicesAvailable. ...

Code returned from isGooglePlayServicesAvailable. Google Play services is not installed on the device.

  • 3.4.1
Modules.CloudPush
: Numberreadonly
Code returned from isGooglePlayServicesAvailable. ...

Code returned from isGooglePlayServicesAvailable. Google Play services is out of date.

  • 3.4.1
Modules.CloudPush
: Numberreadonly
Code returned from isGooglePlayServicesAvailable. ...

Code returned from isGooglePlayServicesAvailable. Google Play services is available, and the connection is successful.

  • 3.4.1
apiName : Stringreadonly

The name of the API that this proxy corresponds to.

The name of the API that this proxy corresponds to.

The value of this property is the fully qualified name of the API. For example, Button returns Ti.UI.Button.

  • 3.2.0
  • 3.2.0
  • 3.2.0
Indicates if the proxy will bubble an event to its parent. ...

Indicates if the proxy will bubble an event to its parent.

Some proxies (most commonly views) have a relationship to other proxies, often established by the add() method. For example, for a button added to a window, a click event on the button would bubble up to the window. Other common parents are table sections to their rows, table views to their sections, and scrollable views to their views. Set this property to false to disable the bubbling to the proxy's parent.

Default: true

  • 3.0.0
  • 3.0.0
  • 3.0.0
Modules.CloudPush
: Booleandeprecated
Whether or not this device will receive push notifications. ...

Whether or not this device will receive push notifications.

deprecated

3.2.0 This property was only required to enable push notifications for the legacy MQTT protocol.

Default: false

Modules.CloudPush
: Boolean
Whether or not your application is brought to the foreground whenever a new push is received. ...

Whether or not your application is brought to the foreground whenever a new push is received.

Note that this behavior is rather disruptive to users, and is strongly discouraged.

Default: false

The Window or TabGroup whose Activity lifecycle should be triggered on the proxy.

The Window or TabGroup whose Activity lifecycle should be triggered on the proxy.

If this property is set to a Window or TabGroup, then the corresponding Activity lifecycle event callbacks will also be called on the proxy. Proxies that require the activity lifecycle will need this property set to the appropriate containing Window or TabGroup.

  • 3.6.0
Modules.CloudPush
: Boolean
Whether or not clicking the tray notification will bring your application to the foreground. ...

Whether or not clicking the tray notification will bring your application to the foreground.

This is only applicable if you have set showTrayNotification to true.

Default: true

Modules.CloudPush
: Boolean
Whether or not to show a tray notification when a new push is received. ...

Whether or not to show a tray notification when a new push is received.

If your payload is only a string, it will be used as the contentText and tickerText, and your application's name will be used as the contentTitle with a system icon.

Note that in your payload, you can customize this tray notification using any of the properties of a Titanium.Android.Notification, except for contentIntent and deleteIntent (those are automatically set).

Default: true

Modules.CloudPush
: Boolean
Whether or not to show tray notifications when your application is in the foreground. ...

Whether or not to show tray notifications when your application is in the foreground.

Instead of showing a notification, the callback event will be immediately fired instead.

This is only applicable if you have set showTrayNotification to true.

Default: false

Modules.CloudPush
: Boolean
Set to true to trigger a single callback for the selected push notification when multiple push notifications are disp...

Set to true to trigger a single callback for the selected push notification when multiple push notifications are displayed in the tray.

In previous versions of the module, clicking on one of the application's push notifications triggered the callbacks for all of the application's push notifications. The new module retains the same behavior by default.

Set this property to true to receive a single callback for the push notification selected by the user, regardless of how many push notifications are displayed in the tray.

Default: false

Defined By

Methods

Adds the specified callback as an event listener for the named event. ...

Adds the specified callback as an event listener for the named event.

Parameters

  • name : String

    Name of the event.

  • callback : Callback<Object>

    Callback function to invoke when the event is fired.

Returns

  • void
Applies the properties to the proxy. ...

Applies the properties to the proxy.

Properties are supplied as a dictionary. Each key-value pair in the object is applied to the proxy such that myproxy[key] = value.

  • 3.0.0
  • 3.0.0
  • 3.0.0

Parameters

  • props : Dictionary

    A dictionary of properties to apply.

Returns

  • void
Modules.CloudPush
( )
Clears the CloudPush module's stored status, including the push type, device token, GCM sender ID, etc. ...

Clears the CloudPush module's stored status, including the push type, device token, GCM sender ID, etc.

This method is useful to transfer the push type from MQTT to GCM, or changing the GCM sender ID when needed. After calling this method, the CloudPush module is reinitialized. Use retrieveDeviceToken to get the device token again.

  • 3.1.2

Returns

  • void
Fires a synthesized event to any registered listeners. ...

Fires a synthesized event to any registered listeners.

Parameters

  • name : String

    Name of the event.

  • event : Dictionary

    A dictionary of keys and values to add to the Titanium.Event object sent to the listeners.

Returns

  • void
Gets the value of the apiName property. ...

Gets the value of the apiName property.

  • 3.2.0
  • 3.2.0
  • 3.2.0

Returns

  • String
Gets the value of the bubbleParent property. ...

Gets the value of the bubbleParent property.

  • 3.0.0
  • 3.0.0
  • 3.0.0

Returns

  • Boolean
Modules.CloudPush
( ) : Booleandeprecated
Gets the value of the enabled property. ...

Gets the value of the enabled property.

deprecated

3.2.0 This property was only required to enable push notifications for the legacy MQTT protocol.

Returns

  • Boolean
Modules.CloudPush
( ) : Boolean
Gets the value of the focusAppOnPush property. ...

Gets the value of the focusAppOnPush property.

Returns

  • Boolean
Gets the value of the lifecycleContainer property. ...

Gets the value of the lifecycleContainer property.

  • 3.6.0

Returns

Modules.CloudPush
( ) : Boolean
Gets the value of the showAppOnTrayClick property. ...

Gets the value of the showAppOnTrayClick property.

Returns

  • Boolean
Modules.CloudPush
( ) : Boolean
Gets the value of the showTrayNotification property. ...

Gets the value of the showTrayNotification property.

Returns

  • Boolean
Modules.CloudPush
( ) : Boolean
Gets the value of the showTrayNotificationsWhenFocused property. ...

Gets the value of the showTrayNotificationsWhenFocused property.

Returns

  • Boolean
Modules.CloudPush
( ) : Boolean
Gets the value of the singleCallback property. ...

Gets the value of the singleCallback property.

Returns

  • Boolean
Modules.CloudPush
( ) : Number
Returns a code to indicate whether Google Play Services is available on the device. ...

Returns a code to indicate whether Google Play Services is available on the device.

  • 3.4.1

Returns

Removes the specified callback as an event listener for the named event. ...

Removes the specified callback as an event listener for the named event.

Multiple listeners can be registered for the same event, so the callback parameter is used to determine which listener to remove.

When adding a listener, you must save a reference to the callback function in order to remove the listener later:

var listener = function() { Ti.API.info("Event listener called."); }
window.addEventListener('click', listener);

To remove the listener, pass in a reference to the callback function:

window.removeEventListener('click', listener);

Parameters

  • name : String

    Name of the event.

  • callback : Callback<Object>

    Callback function to remove. Must be the same function passed to addEventListener.

Returns

  • void
Modules.CloudPush
( config )
Asynchronously retrieves the application specific device token. ...

Asynchronously retrieves the application specific device token.

This token is used in calls to Appcelerator Cloud Services to subscribe or unsubscribe to push notification channels. This token is unique to each application and device.

Parameters

Returns

  • void
Sets the value of the bubbleParent property. ...

Sets the value of the bubbleParent property.

  • 3.0.0
  • 3.0.0
  • 3.0.0

Parameters

  • bubbleParent : Boolean

    New value for the property.

Returns

  • void
Modules.CloudPush
( enabled )deprecated
Sets the value of the enabled property. ...

Sets the value of the enabled property.

deprecated

3.2.0 This property was only required to enable push notifications for the legacy MQTT protocol.

Parameters

  • enabled : Boolean

    New value for the property.

Returns

  • void
Modules.CloudPush
( focusAppOnPush )
Sets the value of the focusAppOnPush property. ...

Sets the value of the focusAppOnPush property.

Parameters

  • focusAppOnPush : Boolean

    New value for the property.

Returns

  • void
Sets the value of the lifecycleContainer property. ...

Sets the value of the lifecycleContainer property.

  • 3.6.0

Parameters

Returns

  • void
Modules.CloudPush
( showAppOnTrayClick )
Sets the value of the showAppOnTrayClick property. ...

Sets the value of the showAppOnTrayClick property.

Parameters

  • showAppOnTrayClick : Boolean

    New value for the property.

Returns

  • void
Modules.CloudPush
( showTrayNotification )
Sets the value of the showTrayNotification property. ...

Sets the value of the showTrayNotification property.

Parameters

  • showTrayNotification : Boolean

    New value for the property.

Returns

  • void
Modules.CloudPush
( showTrayNotificationsWhenFocused )
Sets the value of the showTrayNotificationsWhenFocused property. ...

Sets the value of the showTrayNotificationsWhenFocused property.

Parameters

  • showTrayNotificationsWhenFocused : Boolean

    New value for the property.

Returns

  • void
Modules.CloudPush
( singleCallback )
Sets the value of the singleCallback property. ...

Sets the value of the singleCallback property.

Parameters

  • singleCallback : Boolean

    New value for the property.

Returns

  • void
Defined By

Events

Modules.CloudPush
Fired whenever a push notification is received. ...

Fired whenever a push notification is received.

If your application is not running when a push is received, the push will be saved in a queue until the next time you add an event listener for this.

This will only be fired once per push notification.

This event will be fired at different times depending on your settings and the application's present state (foreground, background, or not running at all). When focusAppOnPush is true, this will fire as soon as you receive a push. When showTrayNotification is true, this will fire as soon as the user touches the tray notification to focus your application. Or, if showTrayNotificationsWhenFocused is false, and your application is in the foreground, it will be called right away. If both focusAppOnPush and showTrayNotification are false, this will fire the next time your application is launched and you add an event listener for it.

You can use the trayClickLaunchedApp and trayClickFocusedApp events to distinguish between the various ways a push notification can return a user to your application.

Properties

  • payload : String

    A JSON string of your data payload. Use JSON.parse to turn this into an object you can use.

  • source : Object

    Source object that fired the event.

    •  
    •  
    •  
  • type : String

    Name of the event fired.

    •  
    •  
    •  
  • bubbles : Boolean

    True if the event will try to bubble up if possible.

    •  
    •  
    •  
  • cancelBubble : Boolean

    Set to true to stop the event from bubbling.

    •  
    •  
    •  
Modules.CloudPush
Fired when a tray notification is shown and the application is already running. ...

Fired when a tray notification is shown and the application is already running.

Touching it focuses the app, and fires this event.

This is only applicable if you have set showTrayNotification to true.

Properties

  • payload : String

    A JSON string of your data payload. Use JSON.parse to turn this into an object you can use.

  • source : Object

    Source object that fired the event.

    •  
    •  
    •  
  • type : String

    Name of the event fired.

    •  
    •  
    •  
  • bubbles : Boolean

    True if the event will try to bubble up if possible.

    •  
    •  
    •  
  • cancelBubble : Boolean

    Set to true to stop the event from bubbling.

    •  
    •  
    •  
Modules.CloudPush
Fired when a tray notification is shown and the application is not running. ...

Fired when a tray notification is shown and the application is not running.

Touching it launches the app, and fires this event.

This is only applicable if you have set showTrayNotification to true.

Properties

  • payload : String

    A JSON string of your data payload. Use JSON.parse to turn this into an object you can use.

  • source : Object

    Source object that fired the event.

    •  
    •  
    •  
  • type : String

    Name of the event fired.

    •  
    •  
    •  
  • bubbles : Boolean

    True if the event will try to bubble up if possible.

    •  
    •  
    •  
  • cancelBubble : Boolean

    Set to true to stop the event from bubbling.

    •  
    •  
    •