Push Notifications

Enabling User Notifications

The Urban Airship module makes a distinction between "user notifications", which can be seen by the user, and invisible notifications that carry only data for the app to process. Enabling or disabling user notifications is a preference often best left up to the user, so by default, user notifications are disabled.

Enable user notifications
UrbanAirship.userNotificationsEnabled = true;

Launch Notification

The notification that launched the application can be accessed with getLaunchNotification. The notification will contain the message, extras, and the notification ID. Example:

Example of getting the launch notification
// Passing true to getLaunchNotification will clear the notification and
// cause subsequent calls to return null.
var launchNotification = UrbanAirship.getLaunchNotification(true);

Listening for Events

EVENT_CHANNEL_UPDATED
The EVENT_CHANNEL_UPDATED will be emitted when the channel is first created or updated due to registration changes.
Example EVENT_CHANNEL_UPDATED
UrbanAirship.addEventListener(UrbanAirship.EVENT_CHANNEL_UPDATED, function(e) {
    Ti.API.info('Channel Updated' + UrbanAirship.channelId);
});
EVENT_PUSH_RECEIVED
The EVENT_PUSH_RECEIVED will be emitted whenever a push is received when the application is foregrounded. The event will contain the message, extras, and the notification ID (Android only). Example:
Example EVENT_PUSH_RECEIVED
UrbanAirship.addEventListener(UrbanAirship.EVENT_PUSH_RECEIVED, function(e) {
    Ti.API.info('Push received' + e.message);
});