All Projects → andreialecu → node-apn-http2

andreialecu / node-apn-http2

Licence: MIT License
Communicate with Apple Push Notification Service via native Node.js v8.8.1+ HTTP2 module (node-apn drop-in)

Programming Languages

typescript
32286 projects

Projects that are alternatives of or similar to node-apn-http2

apns2
Node client for connecting to Apple's Push Notification Service using the new HTTP/2 protocol with JSON web tokens
Stars: ✭ 66 (+164%)
Mutual labels:  apple, http2, push-notifications, apns
Apns Http2
A Java library for sending notifications via APNS using Apple's HTTP/2 API.
Stars: ✭ 194 (+676%)
Mutual labels:  apple, http2, apns
Go Apns2
Go package for HTTP/2 Apple Push Notification Service.
Stars: ✭ 53 (+112%)
Mutual labels:  apple, http2, apns
Apnotic
A Ruby APNs HTTP/2 gem able to provide instant feedback.
Stars: ✭ 360 (+1340%)
Mutual labels:  apple, http2, apns
Net Core Push Notifications
Lightweight .NET Core Push Notifications for Android and iOS
Stars: ✭ 105 (+320%)
Mutual labels:  apple, push-notifications, apns
Apns2
⚡ HTTP/2 Apple Push Notification Service (APNs) push provider for Go — Send push notifications to iOS, tvOS, Safari and OSX apps, using the APNs HTTP/2 protocol.
Stars: ✭ 2,569 (+10176%)
Mutual labels:  apple, http2, apns
Gunfish
No description or website provided.
Stars: ✭ 35 (+40%)
Mutual labels:  apple, push-notifications, apns
Grocer
Pushing your Apple notifications since 2012.
Stars: ✭ 1,005 (+3920%)
Mutual labels:  apple, push-notifications
Jwt
Kotlin JWT 🔑 implementation (Json Web Token) as required by APNs 🔔 (Apple Push Notifications) or Sign in with Apple 🍏
Stars: ✭ 31 (+24%)
Mutual labels:  apple, apns
Notificato
Takes care of Apple push notifications (APNS) in your PHP projects.
Stars: ✭ 217 (+768%)
Mutual labels:  apple, push-notifications
OneSignal-Ionic-Sample
No description or website provided.
Stars: ✭ 85 (+240%)
Mutual labels:  push-notifications, apns
Pyapns2
Python library for interacting with the Apple Push Notification service (APNs) via HTTP/2 protocol
Stars: ✭ 246 (+884%)
Mutual labels:  apple, apns
mobile-messaging-sdk-ios
Mobile Messaging SDK for iOS
Stars: ✭ 45 (+80%)
Mutual labels:  push-notifications, apns
dotAPNS
dotAPNS is a library used to send push notifications to Apple devices using Apple Push Notification service via HTTP/2 API.
Stars: ✭ 80 (+220%)
Mutual labels:  apple, apns
azure-notificationhubs-java-backend
Azure Notification Hubs SDK for Java
Stars: ✭ 31 (+24%)
Mutual labels:  push-notifications, apns
mobile-push
A push notification library
Stars: ✭ 21 (-16%)
Mutual labels:  push-notifications, apns
Apns
apns is a simple golang package for ios notification based http2 protocol
Stars: ✭ 100 (+300%)
Mutual labels:  http2, apns
Apns4erl
Apple Push Notification Server for Erlang
Stars: ✭ 352 (+1308%)
Mutual labels:  apple, apns
mod push appserver
Simple and extendable appserver for XMPP pushes (aka. XEP-0357)
Stars: ✭ 24 (-4%)
Mutual labels:  push-notifications, apns
aioapns
An efficient APNs Client Library for Python/asyncio
Stars: ✭ 60 (+140%)
Mutual labels:  push-notifications, apns

node-apn-http2

Current Version

A Node.js module for interfacing with the Apple Push Notification service using NATIVE node.js http2 API (requires node v8.8.1+)

This package is supposed to be drop-in compatible with node-apn, however, only token based credentials are supported (p8).

Installation

yarn is the preferred installation method:

$ yarn add node-apn-http2

Load in the module

var apn = require('node-apn-http2');
var options = {
  token: {
    key: "path/to/APNsAuthKey_XXXXXXXXXX.p8",
    keyId: "key-id",
    teamId: "developer-team-id"
  },
  production: false,
  hideExperimentalHttp2Warning: true // the http2 module in node is experimental and will log 
                                     // ExperimentalWarning: The http2 module is an experimental API. 
                                     // to the console unless this is set to true
};

var apnProvider = new apn.Provider(options);

By default, the provider will connect to the sandbox unless the environment variable NODE_ENV=production is set.

Sending a notification

To send a notification you will first need a device token from your app as a string

let deviceToken = "a9d0ed10e9cfd022a61cb08753f49c5a0b0dfb383697bf9f9d750a1003da19c7"
var note = new apn.Notification();

note.expiry = Math.floor(Date.now() / 1000) + 3600; // Expires 1 hour from now.
note.badge = 3;
note.sound = "ping.aiff";
note.alert = "\uD83D\uDCE7 \u2709 You have a new message";
note.payload = {'messageFrom': 'John Appleseed'};
note.topic = "<your-app-bundle-id>";

Send the notification to the API with send, which returns a promise.

apnProvider.send(note, deviceToken).then( (result) => {
  // see documentation for an explanation of result
});

This will result in the the following notification payload being sent to the device

{"messageFrom":"John Appelseed","aps":{"badge":3,"sound":"ping.aiff","alert":"\uD83D\uDCE7 \u2709 You have a new message"}}

You should only create one Provider per-process for each certificate/key pair you have. You do not need to create a new Provider for each notification. If you are only sending notifications to one app then there is no need for more than one Provider.

If you are constantly creating Provider instances in your app, make sure to call Provider.shutdown() when you are done with each provider to release its resources and memory.

Troubleshooting

You are encouraged to read the extremely informative Troubleshooting Push Notifications Tech Note in the first instance, in case your query is answered there.

History

v1.2.0

  • return potential error response body as object instead of string (fixes #4)

v1.1.0

  • add option to hide "ExperimentalWarning: The http2 module is an experimental API." message

v1.0.1

  • fix base64 encoded p8 token string not being correctly identified as a string

v1.0.0

  • returned promise from .send() is now compatible with the one that node-apn normally returned
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].