With the XtremePush module for Titanium you can add XtremePush to both iOS and Android apps built with Titanium.
Platform Specific Information
XtremePush supports push notifications for iOS devices via Apples's Push Notification Service (APNs for short). And push notifications for Android devices via Google’s GCM (Google Cloud Messaging for Android) service. This page contains Titanium specific instructions but It is also recommended you read the native documentation for these platforms.
This includes information on importing the SDKs, initialising the core integration and obtaining and uploading iOS and Android credentials for Push Notifications to the platform.
Advanced features include: tagging of events, custom push notification handling and location services can also be found in the SDKs section.
Note: the max Android level that should be targeted in the app is 25.
XtremePush Titanium SDK Setup
First, download the current Titanium module here. This zip file contains the module.
Next you must add the XtremePush Titanium module to your Titanium installation on your development machine if you have not already done so.
Mac OS X
If you are using Mac OS X copy the modules folder from the distribution zip file into the
~/Library/Application Support/Titanium folder and allow it to merge
If you are running Windows copy the modules folder from the distribution zip file into the
C:\ProgramData\Titanium folder allow it to merge
If working on the Linux copy the modules folder from the distribution zip file into the
~/.titanium folder allow it to merge
Add Xtremepush to your Project in TitaniumStudio
When you have added the modules to your Titanium SDK installation you can use XtremePush in your project.
Modify the tiapp.xml
Import the XtremePush module into your project by double clicking your projects tiapp.xml in TitaniumStudio. You can add the module via the TiApp editor UI by clicking the green add button next to the list of modules,
and selecting XtremPush from the drop down list
you will see XtremePush in the list of modules if you have successfully added it.
You can also add the module by editing tiapp.xml via the raw xml editor
For details on how to connect your iOS app to the xtremepush platform and where to get the XTREME_PUSH_APP_KEY consult the iOS docs here.
If you are adding adding location services make sure to include NSLocationWhenInUseUsageDescription to the plist, in iOS 8.0 and later this is required to Specify the reason for accessing the user’s location information.
For details on how to connect your Android app to the xtremepush platform and where to get the XTREME_PUSH_APP_KEY and your GOOGLE_PROJECT_NUMBER consult the Android docs here.
You must also add the following permissions, android services, receivers and activities under the application tag as required:
Example manifest showing permissions and services used by Xtremepush
Enable in Alloy Application
If you are using Alloy, then you would add the following to your alloy.js file:
You can see in the registration above there are three callback functions (messageResponseCallback, InboxBadgeCallback, deeplinkCallback). Examples of how to use these is shown later
Because of Titanium's new handling of Windows and TabGroups as activities in Android, there are a number of additional options which can be set in your index.js file. Here is a full sample index.js. $.index is the app's main TabGroup and $.b1-14 are example buttons which show some of the options available in the module.
Build your app for iOS or Android and then send your first push using the appropriate instructions:
Xtremepush Callback Functions
They are called to be executed in special cases as explained below:
The response.type variable shown above can be either present | click | dismiss
- present - when a push notification is receved and the app is in the foreground
- click - when a message is clicked
- dismiss - when a message is dismissed
Below is a complete example of custom notification handling. It does multiple things:
- shows a custom dialog when a push message is received in foreground
- opens an article page when a message is clicked
- saves information when one of the message buttons is clicked
note: Every message sent in the campaigns associated with the example below, includes a payload key articleId
happens when the badge number updates. The badge number is checked when:
- New push message arrives
- Application is started
- Inbox window is closed
An example is shown below
happens when a message with the click action 'Go to deeplink' is clicked.
An example is shown below:
Foreground Notification Handling
It is important to define the right behaviour for the situation when a push notification is received in foreground. You don't want to interrupt the user workflow, but still be delivering important information to the user.
The default behaviour on both iOS and Android is to show OS style notification. But this can be changed, by adding the payload with key 'foreground' and value 'false' to your campaign.
Now when the push is received, should the app be in the foreground, the notification will not be displayed.
Retrieving your XtremePush ID
Now that your app is configured for mobile analytics and sending push notifications the final basic feature of XtremePush is retrieving your XtremePush ID. This can be accomplished by calling the deviceInfo method:
This method returns your device's id as obtained from XtremePush server. If your device has not received an id then it has not successfully registered and there is an issue with your integration. If for example you want to quickly output the the device id to the debug area in TitaniumStudio you would use it like this:
Ti.API.debug("deviceInfo" + xtremepush.deviceInfo);
If you successfully retrieve the ID it can be used to identify your device on the platform and to send a push notification to just that device.