All Projects → AndrewBarba → apns2

AndrewBarba / apns2

Licence: MIT license
Node client for connecting to Apple's Push Notification Service using the new HTTP/2 protocol with JSON web tokens

Programming Languages

typescript
32286 projects

Projects that are alternatives of or similar to apns2

node-apn-http2
Communicate with Apple Push Notification Service via native Node.js v8.8.1+ HTTP2 module (node-apn drop-in)
Stars: ✭ 25 (-62.12%)
Mutual labels:  apple, http2, push-notifications, apns
Apnotic
A Ruby APNs HTTP/2 gem able to provide instant feedback.
Stars: ✭ 360 (+445.45%)
Mutual labels:  apple, http2, 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 (+3792.42%)
Mutual labels:  apple, http2, apns
Apns Http2
A Java library for sending notifications via APNS using Apple's HTTP/2 API.
Stars: ✭ 194 (+193.94%)
Mutual labels:  apple, http2, apns
Gunfish
No description or website provided.
Stars: ✭ 35 (-46.97%)
Mutual labels:  apple, push-notifications, apns
Go Apns2
Go package for HTTP/2 Apple Push Notification Service.
Stars: ✭ 53 (-19.7%)
Mutual labels:  apple, http2, apns
Net Core Push Notifications
Lightweight .NET Core Push Notifications for Android and iOS
Stars: ✭ 105 (+59.09%)
Mutual labels:  apple, 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 (+21.21%)
Mutual labels:  apple, apns
Docker Swift Apns
A collection of Docker images to build APNS providers in Swift
Stars: ✭ 34 (-48.48%)
Mutual labels:  http2, apns
Apns4erl
Apple Push Notification Server for Erlang
Stars: ✭ 352 (+433.33%)
Mutual labels:  apple, apns
Airnotifier
Push Notifications Server for Human Beings.
Stars: ✭ 522 (+690.91%)
Mutual labels:  http2, apns
Jwt
Kotlin JWT 🔑 implementation (Json Web Token) as required by APNs 🔔 (Apple Push Notifications) or Sign in with Apple 🍏
Stars: ✭ 31 (-53.03%)
Mutual labels:  apple, apns
Grocer
Pushing your Apple notifications since 2012.
Stars: ✭ 1,005 (+1422.73%)
Mutual labels:  apple, push-notifications
Apns
apns is a simple golang package for ios notification based http2 protocol
Stars: ✭ 100 (+51.52%)
Mutual labels:  http2, apns
Pyapns2
Python library for interacting with the Apple Push Notification service (APNs) via HTTP/2 protocol
Stars: ✭ 246 (+272.73%)
Mutual labels:  apple, apns
OneSignal-Ionic-Sample
No description or website provided.
Stars: ✭ 85 (+28.79%)
Mutual labels:  push-notifications, apns
Onesignal Cordova Sdk
OneSignal is a free push notification service for mobile apps. This plugin makes it easy to integrate your Ionic, PhoneGap CLI, PhoneGap Build, Cordova, or Sencha Touch app with OneSignal. Supports Android, iOS, and Amazon's Fire OS platforms. https://onesignal.com
Stars: ✭ 214 (+224.24%)
Mutual labels:  push-notifications, apns
MongoosePush
MongoosePush is a simple Elixir RESTful service allowing to send push notification via FCM and/or APNS.
Stars: ✭ 101 (+53.03%)
Mutual labels:  http2, apns
Notificato
Takes care of Apple push notifications (APNS) in your PHP projects.
Stars: ✭ 217 (+228.79%)
Mutual labels:  apple, push-notifications
mobile-push
A push notification library
Stars: ✭ 21 (-68.18%)
Mutual labels:  push-notifications, apns

APNS2

npm version Twitter

Node client for connecting to Apple's Push Notification Service using the new HTTP/2 protocol with JSON web tokens.


Create Client

Create an APNS client using a signing key:

import { ApnsClient } from 'apns2'

const client = new ApnsClient({
  team: `TFLP87PW54`,
  keyId: `123ABC456`,
  signingKey: fs.readFileSync(`${__dirname}/path/to/auth.p8`),
  defaultTopic: `com.tablelist.Tablelist`
})

Sending Notifications

Basic

Send a basic notification with message:

import { Notification } from 'apns2'

const bn = new Notification(deviceToken, { alert: 'Hello, World' })

try {
  await client.send(bn)
} catch (err) {
  console.error(err.reason)
}

Send a basic notification with message and options:

import { Notification } from 'apns2'

const bn = new BasicNotification(deviceToken, {
  alert: 'Hello, World',
  badge: 4,
  data: {
    userId: user.getUserId
  }
})

try {
  await client.send(bn)
} catch (err) {
  console.error(err.reason)
}

Silent

Send a silent notification using content-available key:

import { SilentNotification } from 'apns2'

const sn = new SilentNotification(deviceToken)

try {
  await client.send(sn)
} catch (err) {
  console.error(err.reason)
}

Note: Apple recommends that no options other than the content-available flag be sent in order for a notification to truly be silent and wake up your app in the background. Therefore this class does not accept any additional options in the constructor.

Many

Send multiple notifications concurrently:

import { Notification } from 'apns2'

const notifications = [
  new Notification(deviceToken1, { alert: 'Hello, World' }),
  new Notification(deviceToken2, { alert: 'Hello, World' })
]

try {
  await client.sendMany(notifications)
} catch (err) {
  console.error(err.reason)
}

Advanced

For complete control over the push notification packet use the base Notification class:

import { Notification } from 'apns2'

const notification = new Notification(deviceToken, {
  aps: { ... }
})

try {
  await client.send(notification)
} catch(err) {
  console.error(err.reason)
}

Available options can be found at APNS Payload Options

Error Handling

All errors are defined in ./lib/errors.js and come directly from APNS Table 4

You can easily listen for these errors by attaching an error handler to the APNS client:

import { Errors } from 'apns2'

// Listen for a specific error
client.on(Errors.badDeviceToken, (err) => {
  // Handle accordingly...
  // Perhaps delete token from your database
  console.error(err.reason, err.statusCode, err.notification.deviceToken)
})

// Listen for any error
client.on(Errors.error, (err) => {
  console.error(err.reason, err.statusCode, err.notification.deviceToken)
})

Close Connections

If you need to close connections to Apple's APNS servers in order to allow the Node process to exit, you can tear down the APNS client:

await client.close()

Once a client is closed you will not be able to use it again. Instead you should instantiate a new client with new ApnsClient().

Environments

By default the APNS client connects to the production push notification server. This is identical to passing in the options:

const client = new ApnsClient({
  host: 'api.push.apple.com',
  port: 443,
  ...
})

To connect to the development push notification server, pass the options:

const client = new ApnsClient({
  host: 'api.sandbox.push.apple.com'
  ...
})

Requirements

apns2 requires Node.js v16.14 or later

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].