Created
April 20, 2017 12:59
-
-
Save skypanther/2cf9fdebbcb2a3d1e8f2b033b57140ed to your computer and use it in GitHub Desktop.
GCM push test script
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 characters
/* | |
Instructions | |
1. In the same directory where this js file exists, run `npm install gcm` (to install the required node module) | |
2. Get your GCM/FCM API Key from the Google APIs Console and paste it in place of "YOUR_GCM_API_KEY" below | |
2. You'll need your device's push token. You can get this by logging the token when your GCM-enabled app calls | |
the "success" callback after registering for push services. Paste it in place of "YOUR DEVICE_PUSH_TOKEN" below. | |
3. Run this with `node pushtest.js` | |
4. After a moment, you should get the push notification on your device | |
*/ | |
(function (messageId, callback) { | |
var _GCM = require('gcm').GCM, | |
GCM = new _GCM('YOUR_GCM_API_KEY'); | |
var message = { | |
registration_id: 'YOUR_DEVICE_PUSH_TOKEN', | |
'data.title': 'GCM Push Test', | |
'data.alert': 'Is anybody out there?', | |
/* 'data.sound': 'customsound.wav', // file must be in app/platform/android/res/raw */ | |
collapse_key: messageId | |
}; | |
message['data.message'] = message['data.alert']; | |
GCM.send(message, function (err, messageId) { | |
if (err) { | |
console.error('error!'); | |
} | |
callback(0); | |
}); | |
})((new Date()).getTime() + '', process.exit); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment