Push Notification Server
We have stopped working on this project. Consider using pushd instead.
Send push notifications via Google Cloud Messaging or the Apple Push Notification Service
Installation
Install NodeJS and run npm i -g pns
Server Configuration
Create pns.json
:
{
"port": 3005,
"apps": [
{
"appId": "com.example.myapp",
"gcm": {
"apiKey": "xxx...",
"senderID": "123..."
},
"apn": {
"cert": "path/to/cert.pem",
"key": "path/to/key.pem"
}
}
]
}
Configure your firewall to allow outgoing communication on port 2195
:
sudo ufw allow out 2195
App Configuration
- Pick an identifier (e.g.,
com.example.myapp
) - Set the widget id to the identifier in
config.xml
and reset your cordova platforms (cordova prepare android|ios
) - Create a new entry in
pns.json
for your app and set appId to the chosen identifier
iOS (Mac only)
- Create an AppID with the chosen identifier in the iOS Member Center
- Enable Push Notifications for the AppId and generate development or production certificates
- Download and import the certificage into your Keychain
- Export the private key of the certificate via Keychain and run the following command:
openssl x509 -in aps_production.cer -inform DER -outform PEM -out APPID.pem
openssl pkcs12 -in aps_production.p12 -out APPID.key -nodes
- Add the
cert
andkey
paths to the app configuration inpns.json
.
Android
- Register your application on the Google Developer Console
- Add the
apiKey
andsenderId
to the app configuration inpns.json
.
Command Line Usage
Send a message:
pns [appId] [apn|gcm] [token] [title] [message] [payload]
Example:
pns com.example.myapp apn asd... "Hello world!" "This is my first push message." "{\"foo\":\"bar\"}"
Server Usage
Start the server:
pns -s
Send a post request to send a message:
POST http://localhost:3005/send
{
"appId": "com.example.myapp",
"token": "asd...",
"platform": "gcm|apn",
"title": "Hello world!",
"body": "This is my first push message.",
"payload": {
"foo": "bar"
}
}