@Wysie glad you got it going
Parse JS SDK does support push (ios little easier that android - but still ok)
following is my push service for reference just incase it can help
I then have a Admin Dashboard Website that the client uses to send pushes to the app users. This uses the JS SDK also to send the pushes
cheers
.factory('push', function (CommonService, LogService, $http, $ionicPopup) {
return {
registerPush: function (tester) {
LogService.add('Push Register as Tester: ' + tester);
var pushNotification;
pushNotification = window.plugins.pushNotification;
// result contains any message sent from the plugin call
var successHandler = function successHandler (result) {
//alert('Success Handler Result = ' + result);
};
// result contains any error description text returned from the plugin call
var errorHandler = function errorHandler (error) {
//alert('Error Handler Error = ' + error);
};
var tokenHandler = function tokenHandler (result) {
// Your iOS push server needs to know the token before it can push to this device
// here is where you might want to send it the token for later use.
// Rest call to Parse to Insert/Update the Installation record for this Device
$http({
url: "https://api.parse.com/1/installations",
method: "POST",
data: {"deviceType": "ios",
"deviceToken": result,
"testdevice": tester,
"channels": [""] },
headers: {"X-Parse-Application-Id": CommonService.parse_appkey,
"X-Parse-REST-API-Key": CommonService.parse_restkey,
"Content-Type": "application/json"}
}).success(function (data, status, headers, config) {
LogService.add("iOS Token: " + result);
//alert('iOS registered success = ' + data + ' Status ' + status);
}).error(function (data, status, headers, config) {
//alert('iOS register failure = ' + data + ' Status ' + status);
});
};
// iOS
onNotificationAPN = function onNotificationAPN (event) {
LogService.add('onNotificationAPN Triggered');
if ( event.alert ) {
// Note: Popup done differently to gcm but this works for ios
var myPopup = $ionicPopup.alert({
title: CommonService.Title,
template: event.alert
});
myPopup.then(function(res) {
console.log('iOS Message: ' + event.alert);
});
LogService.add("iOS Msg Received. Msg: " + event.alert);
//navigator.notification.alert(event.alert);
}
if ( event.sound ){
var snd = new Media(event.sound);
snd.play();
}
if ( event.badge ) {
pushNotification.setApplicationIconBadgeNumber(successHandler, errorHandler, event.badge);
}
}
// Android
onNotificationGCM = function onNotificationGCM(e) {
LogService.add('onNotificationGCM Triggered: ' + e.event);
//alert('GCM event = ' + e.event);
//TODO : Fix up registering GCM devices and having duplicate gcmRegId's on Installation class if user
// reinstalls app as it will get a new unique InstallationId and therefore write new record.
// Even don't attempt to write/update the record if the installationid and gcmregid haven't changed
// this would require saving them to localstorage to check - InstallationId is already saved to
// localstorage by parse sdk.
switch( e.event )
{
case 'registered':
if ( e.regid.length > 0 )
{
//alert('GCM registered event regid = ' + e.regid);
//alert('Parse InstallationId = ' + CommonService.parseInstallationId);
// Rest call to Parse to Insert/Update the Installation record for this Device
$http({
url: "https://api.parse.com/1/installations",
method: "POST",
data: {"deviceType": "android",
"installationId": CommonService.parseInstallationId,
"gcmRegId": e.regid,
"testdevice": tester,
"channels": [""] },
headers: {"X-Parse-Application-Id": CommonService.parse_appkey,
"X-Parse-REST-API-Key": CommonService.parse_restkey,
"Content-Type": "application/json"}
}).success(function (data, status, headers, config) {
LogService.add("GCM RegID: " + e.regid);
LogService.add("GCM Parse InstallationID: " + CommonService.parseInstallationId);
//alert('GCM registered success = ' + data + ' Status ' + status);
}).error(function (data, status, headers, config) {
//alert('GCM registered failure = ' + data + ' Status ' + status);
});
}
break;
case 'message':
// if this flag is set, this notification happened while we were in the foreground.
// you might want to play a sound to get the user's attention, throw up a dialog, etc.
if ( e.foreground ) {
$ionicPopup.alert({
title: CommonService.Title,
template: e.payload.message
}).then(function(res) {
//console.log('GCM inline notification event' + e.payload.message);
});
LogService.add("GCM Foreground Msg Received. Msg: " + e.payload.message);
//navigator.notification.alert(e.payload.message);
//alert('GCM inline notification event' + e.payload.message);
// if the notification contains a soundname, play it.
//var my_media = new Media("/android_asset/www/"+e.soundname);
//my_media.play();
}
else { // launched because the user touched a notification in the notification tray.
if ( e.coldstart ) {
$ionicPopup.alert({
title: CommonService.Title,
template: e.payload.message
}).then(function(res) {
//console.log('GCM coldstart notification event' + e.payload.message);
});
LogService.add("GCM Coldstart Msg Received. Msg: " + e.payload.message);
//navigator.notification.alert(e.payload.message);
//alert('GCM coldstart notification event' + e.payload.message);
}
else {
$ionicPopup.alert({
title: CommonService.Title,
template: e.payload.message
}).then(function(res) {
//console.log('GCM background notification event' + e.payload.message);
});
LogService.add("GCM Background Msg Received. Msg: " + e.payload.message);
//navigator.notification.alert(e.payload.message);
//alert('GCM background notification event' + e.payload.message);
}
}
//LogService.add("GCM Msg Count: " + e.payload.msgcnt);
//alert('GCM message = ' + e.payload.message);
//alert('GCM msgcnt = ' + e.payload.msgcnt);
break;
case 'error':
LogService.add("GCM Error: " + e.msg);
//alert('GCM error = ' + e.msg);
break;
default:
LogService.add("GCM unknown event");
//alert('GCM unknown event');
break;
}
}
// Do PushPlugin Register here
if ( device.platform == 'android' || device.platform == 'Android' )
{
LogService.add("Push GCM Register Sent");
pushNotification.register(
successHandler,
errorHandler, {
"senderID": CommonService.gcmpush_senderid,
"ecb":"onNotificationGCM"
});
}
else
{
LogService.add("Push iOS Register Sent");
pushNotification.register(
tokenHandler,
errorHandler, {
"badge":"true",
"sound":"true",
"alert":"true",
"ecb":"onNotificationAPN"
});
};
}
};
})