This is a Titanium Mobile Mobile module project that adds PushIO notifications to a project. (http://www.responsys.com/marketing-cloud/products/push-IO)
This module currently only supports iOS. You will need a PushIO account to use this module.
To build the module run the following code from the iphone folder
./build.py
Extract distribution zip file Copy modules/iphone/uk.co.tbp.pushio to ~/Library/Application Support/Titanium/modules/iphone
Register the module with your application by editing tiapp.xml
and adding your module.
Example:
<modules>
<module version="1.0">uk.co.tbp.pushio</module>
</modules>
To access this module from JavaScript, you would do the following:
var push_io = require("uk.co.tbp.pushio");
The push_io variable is a reference to the Module object.
When you run your project, the compiler will combine your module along with its dependencies and assets into the application.
The pushio_config_debug.json file that is created in the PushIO management interface needs to be copied to the assets folder of your titanium application.
PushIO have created a iOS framework for their service. it can be downloaded from
https://github.com/pushio/PushIOManager_iOS
The supported version of the framework has been includede with this module
To build the module run the following code from the iphone folder
./build.py
Use the Ti.Network.registerForPushNotifications method to register for notifications. This is usually placed in alloy.js
var deviceToken = null;
var pushio = require('uk.co.tbp.pushio');
Ti.Network.registerForPushNotifications({
// Specifies which notifications to receive
types : [ Ti.Network.NOTIFICATION_TYPE_BADGE,
Ti.Network.NOTIFICATION_TYPE_ALERT,
Ti.Network.NOTIFICATION_TYPE_SOUND],
success : deviceTokenSuccess,
error : deviceTokenError,
callback : receivePush
});
// Process incoming push notifications
function receivePush(e) {
pushio.recordNotification(e.data);
alert('Received push: ' + JSON.stringify(e));
}
// Save the device token for subsequent API calls
function deviceTokenSuccess(e) {
pushio.registerDevice(e.deviceToken);
deviceToken = e.deviceToken;
}
function deviceTokenError(e) {
alert('Failed to register for push notifications! ' + e.error);
}
A unique ID used by Push IO. You can use this for adding test devices at https://manage.push.io This call will always return a non-null value.
Ti.API.Info(push_io.pushIOUUID);
This section has method calls associated with notification categories.
To register for a category use the registerCategory method on the push_io variable.
push_io.registerCategory('Banana');
To register for multiple categories at once use the registerCategory method on the push_io variable.
push_io.registerCategories(['Apples','Oranges']);
To unregister for a category use the unregisterCategory method on the push_io variable.
push_io.unregisterCategory('Banana');
To unregister for a category use the unregisterCategory method on the push_io variable.
push_io.unregisterCategories(['Apples','Oranges']);
To unregister for a category use the unregisterCategory method on the push_io variable.
push_io.unregisterAllCategories();
The isRegisteredForCategory method can be used to check if you are registered for a category.
if(push_io.isRegisteredForCategory('Bannana')){
Ti.API.Info('We will have been registered for Bannanas');
}
A user identifier can be assosiated with a device. If you are only using PushIO, then they recommend that you use a hash value. However if you need to integrate with Responsys you will need to use the plain value.
The following identifies are supported for Responsys integration.
Phone Number
Customer Id
You must use the same identifier type for all users.
To register a user identifier with a device call the registerUserID method. This is usually done after a successfully logout event.
push_io.registerUserID('[email protected]');
To unregister a user identifier with a device call the unregisterUserID method. This is usually done after a successfully logout event.
push_io.unregisterUserID('[email protected]');
The isRegisteredForUserID method can be used to check if you are registered for the device.
if(push_io.isRegisteredForUserID('[email protected]')){
Ti.API.Info('We will have been associated with this device.');
}
The registeredUserID method returns the current user identifier registered for the device.
push_io.registeredUserID()
Custom engagement metrics can be tracked using the trackEngagementCustomMetric method.
push_io.trackEngagementCustomMetric('Purchased')