map-o file-code-o arrow-directionplatform-webreach-project-type-boarding-passreach-project-type-couponreach-project-type-event-ticketreach-project-type-genericreach-project-type-gift-cardreach-project-type-loyalty-cardreach-project-type-member-card pictures more_vert chain keyboard_arrow_down keyboard_arrow_right

Titanium

The Urban Airship Titanium module allows a developer to integrate push notification services with Titanium apps targeting both Android and iOS. This plugin is designed to be cross-platform, and applications making use of it can leverage the same code on both platforms.

Resources

Setup

Example tiapp.xml:

<ti:app>
    ...

    <modules>
       ...

       <module platform="android">com.urbanairship</module>
       <module platform="iphone">com.urbanairship</module>
    </modules>


    <ios>
        <plist>
            <dict>
                ...
                <key>UIBackgroundModes</key>
                <array>
                    <string>remote-notification</string>
                </array>
            </dict>
        </plist>
    </ios>

    <!-- Production credentials -->
    <property name="com.urbanairship.production_app_key" type="string">Your Production App Key</property>
    <property name="com.urbanairship.production_app_secret" type="string">Your Production App Secret</property>

    <!-- Development credentials -->
    <property name="com.urbanairship.development_app_key" type="string">Your Development App Key</property>
    <property name="com.urbanairship.development_app_secret" type="string">Your Development App Secret</property>

    <!-- Selects between production vs development credentials -->
    <property name="com.urbanairship.in_production" type="bool">false</property>

    <!-- Android -->
    <property name="com.urbanairship.gcm_sender" type="String">GCM Sender ID or Project Number</property>
    <property name="com.urbanairship.notification_icon" type="string">Name of an icon in /project_name/platform/android/res/drawable folders, e.g. ic_notification.png</property>
    <property name="com.urbanairship.notification_accent_color" type="string">Notification accent color, e.g. #ff0000</property>

    <!-- iOS 10 alert foreground notification presentation option -->
    <property name="com.urbanairship.ios_foreground_notification_presentation_alert" type="bool">true | false</property>
    <!-- iOS 10 badge foreground notification presentation option -->
    <property name="com.urbanairship.ios_foreground_notification_presentation_badge" type="bool">true | false</property>
    <!-- iOS 10 sound foreground notification presentation option -->
    <property name="com.urbanairship.ios_foreground_notification_presentation_sound" type="bool">true | false</property>

</ti:app>

Import the module:

var UrbanAirship = require('com.urbanairship')

Start by downloading the latest iOS and Android modules. Modify the tiapp.xml file to include and configure the Urban Airship module.

Send Your First Push Notification

var UrbanAirship = require('com.urbanairship')

UrbanAirship.setUserNotificationsEnabled(true)

At this point in the guide, if you followed all the steps above you should be ready to send a test push notification to verify everything is set up properly.

Before sending a push, you must enable user notifications. The module does not enable user notifications by default in order to avoid prompting the user for permissions. But for a testing purposes, you can enable user notifications as soon as the application is ready. You may also want to set default foreground presentation options to display the notification in the foreground on iOS 10. On older iOS devices, make sure you background the app before sending the push.

Urban Airship Channel IDs

var channelId = UrbanAirship.channelId;

The Channel ID is a unique identifier that ties together an application/device pair on a mobile device. The Channel ID is used to target pushes to specific devices using the Urban Airship API. Once a Channel ID is created, it will persist the application until it is either reinstalled, or its internal data is cleared.

Don’t worry if this value initially comes back as null on your app’s first run (or after clearing the application data), as the Channel ID will be created and persisted during registration. To receive an event when the Channel ID is created, see Listening for Events.

Enabling User Notifications

UrbanAirship.userNotificationsEnabled = true;

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.

Listening for Events

EVENT_CHANNEL_UPDATED:

UrbanAirship.addEventListener(UrbanAirship.EVENT_CHANNEL_UPDATED, function(e) {
    Ti.API.info('Channel Updated' + UrbanAirship.channelId);
});

EVENT_PUSH_RECEIVED:

UrbanAirship.addEventListener(UrbanAirship.EVENT_PUSH_RECEIVED, function(e) {
    Ti.API.info('Push received' + e.message);
});
EVENT_CHANNEL_UPDATED
The EVENT_CHANNEL_UPDATED will be emitted when the channel is first created or updated due to registration changes.
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:

Launch Notification

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

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

Addressing Devices

To help target specific devices or users for a notification, we have Tags, Named Users and Tag Groups.

Tags

// Set tags
UrbanAirship.tags = ["some-tag", "other-tag"];

Tags allow you to attribute arbitrary metadata to a specific device. Common examples include favorites such as sports teams or news story categories.

Named Users

UrbanAirship.namedUser = "coolNamedUserId";

Named Users allow you to associate multiple devices to a single user or profile that may be associated with more than one device, e.g., an end-user’s Android phone and tablet. A device can have only one Named User, and a single Named User should not be associated with more than 20 devices.

By default, Named Users cannot be associated from the device. In this case if the devices attempts a Named User association, the association will fail and the plugin will log an error. In order to change this setting, see the Settings documentation.

Associating the channel with a Named User ID, will implicitly disassociate the channel from the previously associated Named User ID, if it existed.

Custom Events

 var customEvent = {
    event_name: 'customEventName',
    event_value: 2016,
    transaction_id: 'customTransactionId',
    interaction_id: 'customInteractionId',
    interaction_type: 'customInteractionType',
    properties: {
        someBoolean: true,
        someDouble: 124.49,
        someString: "customString",
        someInt: 5,
        someLong: 1234567890,
        someArray: ["tangerine", "pineapple", "kiwi"]
    }
};

var customEventPayload = JSON.stringify(customEvent);
UrbanAirship.addCustomEvent(customEventPayload);

Custom events let you track user activities and key conversions in your application, and tie them back to corresponding push messaging campaigns. Custom events requires analytics to be enabled. If disabled, any event that is added to analytics will be ignored. For a more detailed explanation on custom events and possible use cases, see the Custom Events topic guide.

Message Center

The default message center can be displayed at any time.

UrbanAirship.displayMessageCenter();

Urban Airship Message Center is a place in your app where you can display persistent rich messages, including HTML, video, etc. The messages are hosted by Urban Airship, and are typically displayed in standard inbox-style within your app.

Never miss out on product updates

Click "Allow" in the browser prompt in the upper left hand corner of your browser.

Next, we'll allow you to choose what sort of notifications you'd like to receive.

Choose your notification topics

Product Subscription Options

    Platform Subscription Options