Last active
January 26, 2017 09:50
-
-
Save davydes/60bcd08343d3dc00e408f9b7c842540a to your computer and use it in GitHub Desktop.
Revisions
-
davydes revised this gist
Jan 26, 2017 . 1 changed file with 2 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,3 +1,5 @@ // Plugin homepage https://github.com/phonegap/phonegap-plugin-push var app = { initialize() { document.addEventListener('deviceready', this.onDeviceReady.bind(this), false); -
davydes revised this gist
Jan 26, 2017 . No changes.There are no files selected for viewing
-
davydes created this gist
Jan 26, 2017 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,74 @@ 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();