push-notification
Installation
$ npm install --save push-notification
Usage
const PushNotification = ;const DeviceType = PushNotificationDeviceType; const pn = ; const data = title: 'Title' message: 'Message' badge: '' sound: '' payload: param1: 'additional data' param2: 'another data' ; pn; // push to single ios devicepn; // push to multiple ios devices pn; // push to single ios devicepn; // push to multiple ios devices pn; // push to single android devicepn; // push to multiple android devices pn; // push to single android devicepn; // push to multiple android devices const devices = token: 'token1' type: DeviceTypeIOS token: 'token2' type: DeviceTypeANDROID ; // send notification to all devicesPromisealldevices; // or this might be more performant const iosTokens = devices;const andTokens = devices;Promiseall iosTokenslength ? pn : Promise andTokenslength ? pn : Promise;
push, pushToAPN, pushToGCM return Promise instance
pn;
Reference
PushNotification(options)
Arguments
options
- apn
- cert: path to cert.pem
- key: path to key.pem
- gcm
- apiKey
pushToAPN(tokens, data)
Arguments
tokens
- (string) a device token
- (array) array of device tokens
data
- title
- message
- badge
- sound
- (object) payload
Returns
Promise
resolves push result
pushToGCM(tokens, data)
Arguments
tokens
- (string) a device token
- (array) array of device tokens
data
- title
- message
- badge
- sound
- (object) payload
Returns
Promise
resolves push result
push(tokens, data, type)
Arguments
tokens
- (string) a device token
- (array) array of device tokens
data
- title
- message
- badge
- sound
- (object) payload
type
- (DeviceType) DeviceType.IOS or DeviceType.ANDROID
Returns
Promise
resolves push result
Configuring APN and GCM
APN
GCM
License
MIT © Dongwon Lim