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.setUserNotificationsEnabled(true)

Listening for Events

notificationResponse
UrbanAirship.addListener("notificationResponse", (response) => {
  console.log('Notification response: ', JSON.stringify(response.notification));
  console.log('Notification response isForeground: ', response.isForeground);

  // will only be set for notification action buttons
  console.log('Notification response actionId: ', response.actionId);
});
pushReceived
UrbanAirship.addListener("pushReceived", (notification) => {
  console.log('Received push: ', JSON.stringify(notification));
});
deepLink
UrbanAirship.addListener("deepLink", (event) => {
  console.log('Deep link: ', event.deepLink);
});
register
UrbanAirship.addListener("register", (event) => {
  console.log('Channel registration updated: ', event.channelId);
  console.log('Registration token: ', event.registrationToken);
});
notificationOptInStatus
UrbanAirship.addListener("notificationOptInStatus", (event) => {
  console.log('User notifications opted in: ', event.optIn);

  // iOS only
  console.log('User notifications options: ', JSON.stringify(event.notificationOptions));
});
inboxUpdated
UrbanAirship.addListener("inboxUpdated", (event) => {
  console.log('Message center updated. Unread count: ' + event.messageUnreadCount + 'Total message count: ' + event.messageCount);
});

Available events:

notificationResponse
Event fired when a user responds to a notification from either tapping the main notification or one of the action buttons.
pushReceived
Event fired when a push is received.
deepLink
Event fired when a new deep link is available. The app should navigate to the proper page when the event is received.
register
Event fired when channel registration updates.
notificationOptInStatus
Event fired when a user notification opt-in status changes. This event only fires in the foreground and for iOS devices includes the alert, sound, and badge opted-in options.
inboxUpdated
Event fired when the inbox is updated. The event includes the total message count and the total unread message count.