// Plugin homepage https://github.com/phonegap/phonegap-plugin-push var app = { initialize() { document.addEventListener('deviceready', this.onDeviceReady.bind(this), false); }, addPushService() { if(window.PushNotification){ PushNotification.hasPermission((data) => { if (data.isEnabled) { console.log('Push isEnabled'); this.push = PushNotification.init({ "android": { "senderID": "1066475541683" }, "ios": { "alert": "true", "badge": "true", "sound": "true" } }); this.push.on('notification', (data) => { console.log(data.message); console.log(data.title); console.log(data.count); console.log(data.sound); console.log(data.image); console.log(data.additionalData); }); this.push.on('registration', (data) => { let url = 'http://parse-server.flynn.molinos.ru/parse/installations'; let token = data.registrationId; let body = { deviceType: "android", deviceToken: token, userId: "Some id of current user" } body = JSON.stringify(body); console.log("Request body: " + body); let xhr = new XMLHttpRequest(); xhr.open("POST", url, true); xhr.setRequestHeader('Content-Type', 'application/json'); xhr.setRequestHeader('X-Parse-Application-Id', '123'); xhr.setRequestHeader('X-Parse-Master-Key', '123'); xhr.onreadystatechange = function() { if (xhr.readyState == 4) { if(xhr.status == 200 || xhr.status == 201) { console.log("Registering NEW device successfull"); console.log("Response: " + xhr.responseText); } else { console.log("Ups, we are screwed!"); } } } xhr.send(body); }); } }); } }, onDeviceReady() { console.log('device ready'); this.addPushService(); } }; app.initialize();