Yes you can use it with your self-hosted server or any other cloud services like Parse.com or Appcelerator cloud.
Download the latest distribution ZIP-file with latest Android GCM module and consult the Titanium Documentation on how install it, or simply use the gitTio CLI:
$ gittio install ti-push-notification
Titanium has APIs for iOS push notifications, but unfortunately you need module to for Android.
- Install this CommonJS module
Note: Android GCM module will be installed automaticly
$ gittio install ti-push-notification
- Add this code into your app.js or alloy.js
if (Ti.Platform.name === 'android') {
// set android-only options
var pnOptions = {
senderId: 'XXXXXXXX', // It's the same as your project id
notificationSettings: {
sound: 'mysound.mp3', // Place soudn file in platform/android/res/raw/mysound.mp3
smallIcon: 'appicon.png', // Place icon in platform/android/res/drawable/notification_icon.png
largeIcon: 'appicon.png', // Same
vibrate: true, // Whether the phone should vibrate
insistent: true, // Whether the notification should be insistent
group: 'News', // Name of group to group similar notifications together
localOnly: false, // Whether this notification should be bridged to other devices
priority: 2 // Notification priority, from -2 to 2
}
};
} else if (Ti.Platform.name === 'iPhone OS') { // set ios-only options.
// Sets interactive notifications as well if iOS8 and above. Interactive notifications is optional.
if (parseInt(Ti.Platform.version.split(".")[0], 10) >= 8) {
var thumbUpAction = Ti.App.iOS.createUserNotificationAction({
identifier: "THUMBUP_IDENTIFIER",
title: "Agree",
activationMode: Ti.App.iOS.USER_NOTIFICATION_ACTIVATION_MODE_BACKGROUND,
destructive: false,
authenticationRequired: false
});
var thumbDownAction = Ti.App.iOS.createUserNotificationAction({
identifier: "THUMBDOWN_IDENTIFIER",
title: "Disagree",
activationMode: Ti.App.iOS.USER_NOTIFICATION_ACTIVATION_MODE_BACKGROUND,
destructive: false,
authenticationRequired: false
});
var thumbUpDownCategory = Ti.App.iOS.createUserNotificationCategory({
identifier: "THUMBUPDOWN_CATEGORY",
// The following actions will be displayed for an alert dialog
actionsForDefaultContext: [thumbUpAction, thumbDownAction],
// The following actions will be displayed for all other notifications
actionsForMinimalContext: [thumbUpAction, thumbDownAction]
});
var pnOptions = {
types: [Ti.App.iOS.USER_NOTIFICATION_TYPE_ALERT, Ti.App.iOS.USER_NOTIFICATION_TYPE_SOUND],
categories: [thumbUpDownCategory]
};
} else { //No support for interactive notifications, omit categories
var pnOptions = {
types: [Ti.App.iOS.USER_NOTIFICATION_TYPE_ALERT, Ti.App.iOS.USER_NOTIFICATION_TYPE_SOUND]
};
}
}
// set cross-platform event
var onReceive = function(event) {
// Your code here
};
// Create instance with base url
var tiPush = require('ti-push-notification').init({
backendUrl: "http://domain.tld/register.php"
});
// register this device
tiPush.registerDevice({
pnOptions: pnOptions,
onReceive: onReceive,
extraOptions: {
something: "a",
key2: true,
user_id: 1234,
whatever: "youwant"
}
});
Your issues and pull requests are most welcome, also you can pick a task from TODOs.
- Server-side snippets for PHP and NodeJS
- Parse.com example
- Wordpress self-hosted example
- APN Server API setup tutorial
- GCM Server API setup tutorial
- Add option to depend on CaffeinaLab GCM or Jeroen GCM module.
v0.1.3
Add extraOptions
parameter to be uploaded to backend too
v0.1.2
Implementation changed, no need for factory, use init function directly Now module Titaniumified
v0.1.0
Initialed base of ACS Push Notifications
This module is based on ACS Push Notifications CommonJS module by my Ricardo Alcocer.
Original code written in my full-time @ Rize Inno, code open source by Rize Innovations, FZO under MIT license.