Push Notifications

Enabling User Notifications

The Airship SDK makes a distinction between "user notifications", which can be seen by the user, and other forms of push that allow you to send data to your app silently, or in the background. 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
UAirship.setUserNotificationsEnabled(true)

Listening for Events

The JavaScript API follows an asynchronous callback approach with hooks for events such as Push registration and incoming messages.

Example
// Register for any Airship events
document.addEventListener("urbanairship.registration", function (event) {
    if (event.error) {
        console.log('There was an error registering for push notifications')
    } else {
        console.log("Registered with ID: " + event.channelID)
    }
})

// Register for any Airship push events
document.addEventListener("urbanairship.push", function (event) {
    console.log("Incoming push: " + event.message)
})