Skip to content

Instantly share code, notes, and snippets.

@milon120203
Forked from MotiurRahman/index.js
Created January 1, 2020 17:27
Show Gist options
  • Save milon120203/0723d206bc98da7fd8d44dd386d90a34 to your computer and use it in GitHub Desktop.
Save milon120203/0723d206bc98da7fd8d44dd386d90a34 to your computer and use it in GitHub Desktop.
Alloy Push notification Test in Android.
Ti.App.Cloud = require("ti.cloud");
Ti.App.CloudPush = require('ti.cloudpush');
Ti.App.CloudPush.enabled = true;
Ti.App.CloudPush.showTrayNotification = true;
Ti.App.CloudPush.showTrayNotificationsWhenFocused = true;
Ti.App.CloudPush.focusAppOnPush = false;
Ti.App.CloudPush.singleCallback = true;
Ti.App.CloudPush.addEventListener('callback', function(evt) {
alert(evt.payload);
});
Ti.App.CloudPush.addEventListener('trayClickLaunchedApp', function(evt) {
alert('Tray Click Launched App (app was not running)');
});
Ti.App.CloudPush.addEventListener('trayClickFocusedApp', function(evt) {
alert('Tray Click Focused App (app was already running)');
});
function doClick(e) {
Ti.App.CloudPush.retrieveDeviceToken({
success : function(e) {
Ti.API.warn('ENABLE PUSH NOTIFICATION SUCCESS: ' + e.deviceToken);
Ti.App.Cloud.PushNotifications.subscribeToken({
device_token : e.deviceToken,
channel : 'test',
type : 'android'
}, function(e) {
if (e.success) {
alert("Device has been Subscribed");
} else {
Ti.API.warn('ENABLE PUSH NOTIFICATION ERROR: ' + e);
}
});
},
error : function(e) {
Ti.API.warn('ENABLE PUSH NOTIFICATION ERROR: ' + e.error);
}
});
}
function menuClick() {
Alloy.createController('nextWin').getView().open();
}
$.index.open();
<Alloy>
<Window class="container">
<Label id="label" onClick="doClick">Subscribe</Label>
<Label id="label" onClick="menuClick">Go to Next</Label>
</Window>
</Alloy>
var args = $.args;
<Alloy>
<Window class="container">
<Label id="label">Menu</Label>
</Window>
</Alloy>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment