Swiftpack.co - Package - jonblatho/SwiftAPNS

SwiftAPNS

MIT License Swift 4.0, Swift 4.1, Swift 4.2

This package should help with connecting to APNS using token-based authentication in Swift on both macOS and Linux.

This package is particularly useful for deployment in server-side Swift applications and should be integrable with any Swift server like Vapor, Perfect, or Kitura.

Functionality

This package is under active development. Supported functionality is listed below.

  • [x] Generate ES256-signed JWTs for authentication*
  • [x] Encode JSON for APNS payloads
  • [x] Send notifications via APNS
  • [ ] Include localizable strings in APNS payloads
  • [x] Support critical alerts in APNS payloads

* Token generation currently does not work on Ubuntu 18.04. Please use Ubuntu 16.04 in the meantime.

If there is any functionality that you need which isn't listed above, issues and pull requests are very much encouraged.

Generating tokens

This package supports generating tokens only rather than sending notifications. This is useful in developing a token provider server. Recall Apple's guidance regarding token validity:

  • If a previously unused token was used in the past 20 minutes, additional new tokens will be rejected.
  • If the current time is more than an hour later than the time in a token's iat claim, the token will be rejected.

Generating APNS payload JSON

This package also supports generating JSON payloads for use by APNS. As of now, this package is designed to support the vast majority of use cases, but the following use cases are not yet supported:

  • Localizable notifications
  • Critical alerts

Support for these use cases—i.e., the full feature set of APNS—is planned for a future release.

Sending notifications

This package additionally supports sending notifications to a specific device token using APNS. As with the APNS payloads, this package does not yet support every use case, but the vast majority of use cases should be covered.

Additional notes

At this time, this package depends on a branch of IBM's Swift-JWT project which contains incomplete ECDSA support. The branch is under active development and functionality may break at any time. Until support is stable and released on the master branch, use this package at your own risk as this package is not currently intended for mission-critical use.

Converting your APNS key to PEM

When you create a new APNS key for token-based authentication, Apple provides you with a private key in a .p8 file. This library requires you to provide your key as a PEM-encoded private key. To do that, run the following command:

$ openssl ec -in AuthKey_XXXXXXXXXX.p8 -out key.pem

Then, just get the private key into your Swift code and you should then be able to generate tokens or send notifications.

Release notes

Version 0.4.0

Released: 7 February 2019

New:

  • Prepare critical alerts with APNSCriticalAlertPayload.

Version 0.3.0

Released: 6 February 2019

New:

  • Supports all APNS headers like apns-id and apns-expiration

Fixed:

  • content-available pushes would fail

Changed:

  • Removed throwing functions; they now return optionals.
  • Improved inline documentation.
  • APNS.buildURLRequest(...) is now public and can be used to generate a URLRequest for use in sending a push notification.

Removed:

  • Removed deprecated APNSPayload.encoded() method.

Known issues:

  • This package is currently not supported on Ubuntu 18.04. Please use macOS or Ubuntu 16.04.
  • This package currently depends on a branch of IBM's Swift-JWT project which is under active development. Functionality may break at any time, so this package is not recommended for mission-critical use before support is stabilized.

Version 0.2.0

Released: 4 February 2019

New:

  • Use APNS(...).sendNotification(...) and APNS.sendNotification(...) to send notifications.

  • Added APNSPayload.encodedData() method to obtain Data objects with payload JSON. Changed:

  • APNSPayload.encoded() has been renamed to APNSPayload.encodedString(). The old encoded() method remains but will be removed in a future release.

Known issues:

  • This package is currently not supported on Ubuntu 18.04. Please use macOS or Ubuntu 16.04.
  • This package currently depends on a branch of IBM's Swift-JWT project which is under active development. Functionality may break at any time, so this package is not recommended for mission-critical use before support is stabilized.

Version 0.1.0

Released: 4 February 2019

  • Initial release.
  • Supports authentication token encoding and signing on macOS and Ubuntu 16.04.
  • Supports APNS payload encoding for most notifications.

Github

link
Stars: 0
Help us keep the lights on

Dependencies

Used By

Total:

Releases

0.4.0 - Feb 8, 2019

New

  • Prepare critical alerts with APNSCriticalAlertPayload.

0.3.0 - Feb 6, 2019

New

  • Supports all APNS headers like apns-id and apns-expiration (#6)

Fixed

  • content-available pushes would fail (#7)

Changed

  • Removed throwing functions; they now return optionals.
  • Improved inline documentation.
  • APNS.buildURLRequest(...) is now public and can be used to generate a URLRequest for use in sending a push notification.

Removed

  • Removed deprecated APNSPayload.encoded() method.

Known issues

  • This package is currently not supported on Ubuntu 18.04. Please use macOS or Ubuntu 16.04.
  • This package currently depends on a branch of IBM's Swift-JWT project which is under active development. Functionality may break at any time, so this package is not recommended for mission-critical use before support is stabilized.

0.2.0 - Feb 5, 2019

Released: 4 February 2019

New

  • Use the sendNotification(...) methods on APNS to send notifications.
    • Use APNS(...).sendNotification(...) to let APNS handle authentication tokens for you.
    • Use APNS.sendNotification(...) if you are handling authentication tokens yourself (e.g., a provider server).
  • Added APNSPayload.encodedData() method to obtain Data objects with payload JSON.

Changed

  • APNSPayload.encoded() has been renamed to APNSPayload.encodedString(). The old encoded() method remains but will be removed in a future release.

Known issues

  • This package is currently not supported on Ubuntu 18.04. Please use macOS or Ubuntu 16.04.
  • This package currently depends on a branch of IBM's Swift-JWT project which is under active development. Functionality may break at any time, so this package is not recommended for mission-critical use before support is stabilized.

0.1.0 - Feb 4, 2019

Released: 4 February 2019

  • Initial release.
  • Supports authentication token encoding and signing on macOS and Ubuntu 16.04.
  • Supports APNS payload encoding for most notifications.