1.0.4 • Published 6 years ago
pns v1.0.4
Push Notification Server
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 2195App Configuration
- Pick an identifier (e.g.,
com.example.myapp) - Set the widget id to the identifier in
config.xmland reset your cordova platforms (cordova prepare android|ios) - Create a new entry in
pns.jsonfor 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
certandkeypaths to the app configuration inpns.json.
Android
- Register your application on the Google Developer Console
- Add the
apiKeyandsenderIdto 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 -sSend 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"
}
}