# \[Feedback\] NIOAPNS: NIO-based Apple Push Notification Service

**URL:** <https://forums.swift.org/t/feedback-nioapns-nio-based-apple-push-notification-service/24393>\
**Category:** Proposals\
**Created:** [May 10, 2019, 6:09pm UTC](https://forums.swift.org/t/feedback-nioapns-nio-based-apple-push-notification-service/24393 "2019-05-10T18:09:38Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![kylebrowning](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/kylebrowning/32/9837_2.png) [@kylebrowning](https://forums.swift.org/u/kylebrowning)\
**Post date:** [May 10, 2019, 6:09pm UTC](https://forums.swift.org/t/feedback-nioapns-nio-based-apple-push-notification-service/24393/1 "2019-05-10T18:09:38Z")

</div>

After the [discussion thread](https://forums.swift.org/t/discussion-nioapns-nio-based-apple-push-notification-service/23384), we are proposing this as a final revision of this proposal and enter the proposal review phase which will run until the 31st of May 2019.

We have integrated most of the feedback from the discussion thread so even if you have read the previous version, you will find some changes that you hopefully agree with. To highlight a few of the major changes:

- use SSL PointerTricks to fix our usages on OpenSSL 1.1 versus OpenSSL 1.0
- tests have been added
- [more configuration options for APNS provided options](https://github.com/kylebrowning/swift-nio-apns/commit/5f480dd523932de3e379fb9a28dc7870f738ebed)
- documentation
- Naming convention changes
- [Switch to ByteBuffer](https://github.com/kylebrowning/swift-nio-apns/commit/bcff9d96c7e5305a3393d170e1203521fafa7ee1)
- [Switch to in memory signing key](https://github.com/kylebrowning/swift-nio-apns/commit/c8a9d85518c9874ed84c1b8f1603506a51bc77e9)

The feedback model will be very similar to the one known from Swift Evolution. The community is asked to provide feedback in the way outlined below and after the review period finishes, the SSWG will -- based on the community feedback -- decide whether to promote the proposal to the [Sandbox](https://github.com/swift-server/sswg/blob/master/process/incubation.md#process-diagram) maturity level or not.

### What goes into a review of a proposal?

The goal of the review process is to improve the proposal under review through constructive criticism and, eventually, determine the evolution of the server-side Swift ecosystem.

When reviewing a proposal, here are some questions to consider:

- What is your evaluation of the proposal?
- Is the problem being addressed significant enough?
- Does this proposal fit well with the feel and direction of Swift on Server?
- If you have used other languages or libraries with a similar feature, how do you feel that this proposal compares to those?
- How much effort did you put into your review? A glance, a quick reading, or an in-depth study?

Thank you for contributing to the Swift Server Work Group!

### What happens if the proposal gets accepted?

If this proposal gets accepted, a version (likely `0.2.0` ) will be tagged. The development (in form of pull requests) will continue as a regular open-source project.

# NIO-based Apple Push Notification Service

- Proposal: SSWG-0006
- Authors: [Kyle Browning](https://github.com/kylebrowning)
- Sponsor: Vapor
- Review Manager: TBD
- Status: **Implemented**
- Implementation: [kylebrowning/swift-nio-apns](https://github.com/kylebrowning/swift-nio-apns)
- Forum Threads: [Pitch](https://forums.swift.org/t/apple-push-notification-service-implementation-pitch/20193), [Discussion](https://forums.swift.org/t/discussion-nioapns-nio-based-apple-push-notification-service/23384)

## Package Description

Apple push notification service implementation built on Swift NIO.

| | |
| --- | --- |
| **Package name** | `nio-apns` |
| **Module Name** | `NIOAPNS` |
| **Status** | Active review (10th...31st May, 2019) |
| **Proposed Maturity Level** | [Sandbox](https://github.com/swift-server/sswg/blob/master/process/incubation.md#process-diagram) |
| **License** | [Apache 2](https://www.apache.org/licenses/LICENSE-2.0.html) |
| **Dependencies** | [SwiftNIO](https://github.com/apple/swift-nio) 2.x, [SwiftNIOSSL](https://github.com/apple/swift-nio-ssl.git) 2.x, [SwiftNIOHTTP2](https://github.com/apple/swift-nio-http2.git) 1.x |

## Introduction

`NIOAPNS` is a module thats gives server side swift applications the ability to use the [Apple push notification service.](https://developer.apple.com/documentation/usernotifications/setting_up_a_remote_notification_server)

## Motivation

APNS is used to push billions of pushes a day, (7 billion per day in 2012). Many of us using Swift on the backend are using it to power our iOS applications. Having a community supported APNS implementation would go a long way to making it the fastest, free-ist, and simplest solution that exists.

All of the currently maintained libraries either have framework specific dependencies, are not built with NIO, or do not provide enough extensibility while providing "out of the box" capabilities.

## Proposed Solution

`NIOAPNS` provides the essential types for interacting with APNS Server (both production and sandbox).

### What it does do

- Provides an API for handling connection to Apples HTTP2 APNS server.
- Provides proper error messages that APNS might respond with.
- Uses custom/non dependency implementations of JSON Web Token specific to APNS (using [rfc7519](https://tools.ietf.org/html/rfc7519).
- Imports OpenSSL for SHA256 and ES256.
- Provides an interface for signing your Push Notifications.
- Signs your token request.
- Sends push notifications to a specific device.
- [Adheres to guidelines Apple Provides.](https://developer.apple.com/documentation/usernotifications/setting_up_a_remote_notification_server/establishing_a_token-based_connection_to_apns)

### What it won't do.

- Store/register device tokens.
- Build an HTTP2 generic client.
- Google Cloud Message.
- Refresh your token no more than once every 20 minutes and no less than once every 60 minutes. (up to connection handler)

### Future considerations and dependencies

- BoringSSL
- swift-log
- swift-metrics
- swift-jwt?
- swift-http2-client?

### APNSConfiguration

[`APNSConfiguration`](https://github.com/kylebrowning/swift-nio-http2-apns/blob/master/Sources/NIOAPNS/APNSConfiguration.swift) is a structure that provides the system with common configuration.

```swift
public struct APNSConfiguration {
    public var keyIdentifier: String
    public var teamIdentifier: String
    public var signer: APNSSigner
    public var topic: String
    public var environment: Environment
    public var tlsConfiguration: TLSConfiguration

    public var url: URL {
        switch environment {
        case .production:
            return URL(string: "https://api.push.apple.com")!
        case .sandbox:
            return URL(string: "https://api.development.push.apple.com")!
        }
    }

```

#### Example `APNSConfiguration`

```swift
let signer = ...
let apnsConfig = try APNSConfiguration(keyIdentifier: "9UC9ZLQ8YW",
                                   teamIdentifier: "ABBM6U9RM5",
                                   signer: signer),
                                   topic: "com.grasscove.Fern",
                                   environment: .sandbox)

```

### Signer

[`APNSSigner`](https://github.com/kylebrowning/swift-nio-http2-apns/blob/master/Sources/NIOAPNS/APNSSigner.swift) provides a structure to sign the payloads with. This should be loaded into memory at the configuration level. It requires the data to be in a ByteBuffer format. We've provided a convenience initializer for users to do this from filePath. This should only be done once, and not on an EventLoop.

```swift
let signer = try! APNSSigner(filePath: "/Users/kylebrowning/Downloads/AuthKey_9UC9ZLQ8YW.p8")

```

### APNSConnection

[`APNSConnection`](https://github.com/kylebrowning/swift-nio-http2-apns/blob/master/Sources/NIOAPNS/APNSConnection.swift) is a class with methods thats provides a wrapper to NIO's ClientBootstrap. The `swift-nio-http2` dependency is utilized here. It also provides a function to send a notification to a specific device token string.

#### Example `APNSConnection`

```swift
let apnsConfig = ...
let apns = try APNSConnection.connect(configuration: apnsConfig, on: group.next()).wait()

```

### Alert

[`Alert`](https://github.com/kylebrowning/swift-nio-http2-apns/blob/master/Sources/NIOAPNS/APNSRequest.swift) is the actual meta data of the push notification alert someone wishes to send. More details on the specifics of each property are provided [here](https://developer.apple.com/library/archive/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/PayloadKeyReference.html). They follow a 1-1 naming scheme listed in Apple's documentation

#### Example `Alert`

```swift
let alert = Alert(title: "Hey There", subtitle: "Full moon sighting", body: "There was a full moon last night did you see it")

```

### APSPayload

[`APSPayload`](https://github.com/kylebrowning/swift-nio-http2-apns/blob/master/Sources/NIOAPNS/APNSRequest.swift) is the meta data of the push notification. Things like the alert, badge count. More details on the specifics of each property are provided [here](https://developer.apple.com/library/archive/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/PayloadKeyReference.html). They follow a 1-1 naming scheme listed in Apple's documentation

#### Example `APSPayload`

```swift
let alert = ...
let aps = APSPayload(alert: alert, badge: 1, sound: .normal("cow.wav"))

```

## Putting it all together

```swift
let group = MultiThreadedEventLoopGroup(numberOfThreads: 1)
let url = URL(fileURLWithPath: "/Users/kylebrowning/Downloads/AuthKey_9UC9ZLQ8YW.p8")
let data: Data
do {
    data = try Data(contentsOf: url)
} catch {
    throw APNSError.SigningError.certificateFileDoesNotExist
}
var byteBuffer = ByteBufferAllocator().buffer(capacity: data.count)
byteBuffer.writeBytes(data)
let signer = try! APNSSigner.init(buffer: byteBuffer)

let apnsConfig = APNSConfiguration(keyIdentifier: "9UC9ZLQ8YW",
                                       teamIdentifier: "ABBM6U9RM5",
                                       signer: signer,
                                       topic: "com.grasscove.Fern",
                                       environment: .sandbox)

let apns = try APNSConnection.connect(configuration: apnsConfig, on: group.next()).wait()
let alert = Alert(title: "Hey There", subtitle: "Full moon sighting", body: "There was a full moon last night did you see it")
let aps = APSPayload(alert: alert, badge: 1, sound: .normal("cow.wav"))
let notification = BasicNotification(aps: aps)
let res = try apns.send(notification, to: "de1d666223de85db0186f654852cc960551125ee841ca044fdf5ef6a4756a77e").wait()
try apns.close().wait()
try group.syncShutdownGracefully()

```

### Custom Notification Data

Apple provides engineers with the ability to add custom payload data to each notification. In order to facilitate this we have the `APNSNotification`.

#### Example

```swift
struct AcmeNotification: APNSNotification {
    let acme2: [String]
    let aps: APSPayload

    init(acme2: [String], aps: APSPayload) {
        self.acme2 = acme2
        self.aps = aps
    }
}

let apns: APNSConnection: = ...
let aps: APSPayload = ...
let notification = AcmeNotification(acme2: ["bang", "whiz"], aps: aps)
let res = try apns.send(notification, to: "de1d666223de85db0186f654852cc960551125ee841ca044fdf5ef6a4756a77e").wait()

```

## Maturity

We are requesting a [Sandbox](https://github.com/swift-server/sswg/blob/master/process/incubation.md#process-diagram) maturity level

This package meets the following criteria according to the [SSWG Incubation Process](https://github.com/swift-server/sswg/blob/master/process/incubation.md):

- Ecosystem (SwiftNIO)
- Code Style is up to date
- Errors implemented
- Tests being used
- documentation
- [Apache 2 license](https://github.com/kylebrowning/swift-nio-apns/blob/master/LICENSE)
- [Swift Code of Conduct](https://github.com/kylebrowning/swift-nio-apns/blob/master/CODE_OF_CONDUCT.md)
- [Contributing Guide](https://github.com/kylebrowning/swift-nio-apns/blob/master/CONTRIBUTING.md)
- [CircleCI builds](https://circleci.com/gh/kylebrowning/swift-nio-apns/tree/master)

## Alternatives Considered

N/A

---

<div class="post-metadata">

**Author:** ![t089](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/t089/32/40449_2.png) [@t089](https://forums.swift.org/u/t089)\
**Post date:** [May 10, 2019, 7:53pm UTC](https://forums.swift.org/t/feedback-nioapns-nio-based-apple-push-notification-service/24393/2 "2019-05-10T19:53:03Z")

</div>

I think the overall design and API makes a lot of sense and fits well in NIO server land. I have one specific use case that is currently not supported though (I think): Let's assume you want to build an APNS "relay" micro service for your deployment / organization. This service would establish and maintain the authenticated connection to APNS and relay push requests from other services. This service should and can not know what kind of custom payloads the other services might want to send in their notifications. Without having tested it, I believe the current API would not allow this use case, because you always have to send a typed `Notification` through the connection. Or is there a way to send an opaque notification through the APNS connection? Or even better: validation of the "metadata" could happen in this potential relay service but the application specific payload could stay opaque to the connection.

Hm, maybe it is possible to define an `AnyNotification` with something (hacky?) like [AnyCodable](https://github.com/yonaskolb/SwagGen/blob/master/Templates/Swift/Sources/AnyCodable.swift)?

---

<div class="post-metadata">

**Author:** ![kylebrowning](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/kylebrowning/32/9837_2.png) [@kylebrowning](https://forums.swift.org/u/kylebrowning)\
**Post date:** [May 10, 2019, 8:02pm UTC](https://forums.swift.org/t/feedback-nioapns-nio-based-apple-push-notification-service/24393/3 "2019-05-10T20:02:59Z")

</div>

Hrmm, is that not what `APNSNotification` is?

---

<div class="post-metadata">

**Author:** ![t089](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/t089/32/40449_2.png) [@t089](https://forums.swift.org/u/t089)\
**Post date:** [May 10, 2019, 8:15pm UTC](https://forums.swift.org/t/feedback-nioapns-nio-based-apple-push-notification-service/24393/4 "2019-05-10T20:15:24Z")

</div>

But how would you encode/decode custom payload fields in APNSNotification that the app does not know about?

---

<div class="post-metadata">

**Author:** ![kylebrowning](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/kylebrowning/32/9837_2.png) [@kylebrowning](https://forums.swift.org/u/kylebrowning)\
**Post date:** [May 10, 2019, 8:24pm UTC](https://forums.swift.org/t/feedback-nioapns-nio-based-apple-push-notification-service/24393/5 "2019-05-10T20:24:40Z")

</div>

Can you define what you mean by App?

`APNSNotification` is `Codable` so in the bottom of the proposal we have.

```swift
struct AcmeNotification: APNSNotification {
    let acme2: [String]
    let aps: APSPayload

    init(acme2: [String], aps: APSPayload) {
        self.acme2 = acme2
        self.aps = aps
    }
}

```

```swift
/// This is a protocol which allows developers to construct their own Notification payload
public protocol APNSNotification: Codable {
    var aps: APSPayload { get }
}

```

I guess im failing to understand what your needs are.

`Notification` is a generic type that will only invoke this method if it conforms to `APNSNotification` that must be `Codable`

`aps` is the only required property by the APNS, but any custom fields you add are up to you and the Server Side App will fully encode the object it gets as long as it is `Codable`

```swift
public func send<Notification>(_ notification: Notification, to deviceToken: String, expiration: Int? = nil, priority: Int? = nil, collapseIdentifier: String? = nil) -> EventLoopFuture<Void>
        where Notification: APNSNotification

```

---

<div class="post-metadata">

**Author:** ![kylebrowning](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/kylebrowning/32/9837_2.png) [@kylebrowning](https://forums.swift.org/u/kylebrowning)\
**Post date:** [May 10, 2019, 8:31pm UTC](https://forums.swift.org/t/feedback-nioapns-nio-based-apple-push-notification-service/24393/6 "2019-05-10T20:31:39Z")

</div>

I guess what you are saying is you want to be able to make a POST to your micro service with payloads that are not known by the app that is running the NIOAPNS. So how do you decode/encode them into something that conforms to APNSNotification?

---

<div class="post-metadata">

**Author:** ![t089](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/t089/32/40449_2.png) [@t089](https://forums.swift.org/u/t089)\
**Post date:** [May 10, 2019, 8:34pm UTC](https://forums.swift.org/t/feedback-nioapns-nio-based-apple-push-notification-service/24393/7 "2019-05-10T20:34:57Z")

</div>

Exactly, that is what I mean! 🙂

---

<div class="post-metadata">

**Author:** ![kylebrowning](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/kylebrowning/32/9837_2.png) [@kylebrowning](https://forums.swift.org/u/kylebrowning)\
**Post date:** [May 10, 2019, 8:39pm UTC](https://forums.swift.org/t/feedback-nioapns-nio-based-apple-push-notification-service/24393/8 "2019-05-10T20:39:51Z")

</div>

Great question. Not currently possible. I'll have to think about it. Open to suggestions.

Id prefer to say that's not something this library would be able to do, basically it's out of scope.

It could be something that sits on top of this one. Im not sure how much it would benefit everyone that uses this.

All that being said, if there's an easily manageable solution we can come up with, I don't see why not.

---

<div class="post-metadata">

**Author:** ![t089](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/t089/32/40449_2.png) [@t089](https://forums.swift.org/u/t089)\
**Post date:** [May 10, 2019, 9:49pm UTC](https://forums.swift.org/t/feedback-nioapns-nio-based-apple-push-notification-service/24393/9 "2019-05-10T21:49:41Z")

</div>

Another use case might be an app that sends JSON payloads from some NoSQL DB that contains arbitrary user generated data, where the app does not necessarily know all the fields. Maybe not the best idea... but I still think that it is quite a severe limitation that you can not send valid but unknown JSON as payload through this client. I’ll think a bit how this could be supported...

---

<div class="post-metadata">

**Author:** ![lukasa](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/lukasa/32/1232_2.png) [@lukasa](https://forums.swift.org/u/lukasa)\
**Post date:** [May 11, 2019, 6:48am UTC](https://forums.swift.org/t/feedback-nioapns-nio-based-apple-push-notification-service/24393/10 "2019-05-11T06:48:47Z")

</div>

This generally looks really good, thanks so much for the pitch!

One note: you have a type called `APSPayload`: that type really seems like it’s supposed to be called `APNSPayload`. Is there a reason it isn’t?

Otherwise, I’m +1 on this pitch and would recommend having it move forward.

---

<div class="post-metadata">

**Author:** ![tkrajacic](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/tkrajacic/32/1173_2.png) [@tkrajacic](https://forums.swift.org/u/tkrajacic)\
**Post date:** [May 11, 2019, 10:23am UTC](https://forums.swift.org/t/feedback-nioapns-nio-based-apple-push-notification-service/24393/11 "2019-05-11T10:23:54Z")

</div>

As discussed before it is called so because that's what Apple calls it.  
Nobody knows why… 🙂

See the [Documentation](https://developer.apple.com/library/archive/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/PayloadKeyReference.html)

Previous justification: [[Discussion] NIOAPNS: NIO-based Apple Push Notification Service - #8 by kylebrowning](https://forums.swift.org/t/discussion-nioapns-nio-based-apple-push-notification-service/23384/8)

---

<div class="post-metadata">

**Author:** ![bzamayo](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/bzamayo/32/764_2.png) [@bzamayo](https://forums.swift.org/u/bzamayo)\
**Post date:** [May 11, 2019, 12:40pm UTC](https://forums.swift.org/t/feedback-nioapns-nio-based-apple-push-notification-service/24393/12 "2019-05-11T12:40:46Z")

</div>

I think the `APSPayload` type is under-specified. For instance, a way to specify `mutable-content: 1` does not appear to be supported. This is used for iOS rich notification service extensions. The `sound` key can either be a string or a dictionary; the dictionary is used for critical alerts. The currently proposed API only exposes a `String` property. (Here's a more [modern reference](https://developer.apple.com/documentation/usernotifications/setting_up_a_remote_notification_server/generating_a_remote_notification) than the one linked in the source comments.)

Further, `contentAvailable` _is_ a boolean value. I realise the underlying raw value is an integer '1' when encoded, but from an API surface I believe it should be exposed in the `APSPayload` as `Bool`. The same would be true for `mutableContent` — when it is added. I also think there is an argument to name them `hasContentAvailable` and `hasMutableContent`, to better align with Swift naming guidelines.

(Aside: Safari Push Notifications require an additional `url-args` key for the `aps` dictionary, although I'm not sure if Safari notifications support HTTP/2 or if they still require the older binary interface.)

Along that same line, is it a concern that the structures are so tightly coupled to the current push notifications API, specifically for the `APSPayload` and `Alert` types? If Apple adds new notification payload fields in the next version of iOS or macOS, this framework will require changes to keep up on features, or otherwise become obsolete. Apple updates the push notifications API pretty frequently (critical alerts are new in iOS 12, and the mutable content property was added in iOS 10). Maybe it is _too_ tightly coupled?

---

<div class="post-metadata">

**Author:** ![kylebrowning](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/kylebrowning/32/9837_2.png) [@kylebrowning](https://forums.swift.org/u/kylebrowning)\
**Post date:** [May 11, 2019, 2:28pm UTC](https://forums.swift.org/t/feedback-nioapns-nio-based-apple-push-notification-service/24393/13 "2019-05-11T14:28:02Z")

</div>

Thanks for your thoughtful review.

So I'll fix the first points you mention in a PR shortly and post here.

To address the latter part of your comment. I do not believe it to be a concern.

This is an open source library, sponsored by Vapor, and others will have push access. When those things change, we have roughly 6 months from WWDC(June), to September(iOS release) to push an update.

Being tightly coupled allows for less errors, but does requires more effort to maintain longterm. Something Im willing to do and is also the reason pitches require sponsorship, as well as two developers.

Furthermore Im only requesting to be accepted as sandbox level. If we want to graduate to another level, it will require more commiters than just myself.

---

<div class="post-metadata">

**Author:** ![kylebrowning](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/kylebrowning/32/9837_2.png) [@kylebrowning](https://forums.swift.org/u/kylebrowning)\
**Post date:** [May 11, 2019, 2:29pm UTC](https://forums.swift.org/t/feedback-nioapns-nio-based-apple-push-notification-service/24393/14 "2019-05-11T14:29:34Z")

</div>

I believe this was answered for you Cory, but if you have any other questions let me know.

---

<div class="post-metadata">

**Author:** ![bzamayo](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/bzamayo/32/764_2.png) [@bzamayo](https://forums.swift.org/u/bzamayo)\
**Post date:** [May 11, 2019, 2:42pm UTC](https://forums.swift.org/t/feedback-nioapns-nio-based-apple-push-notification-service/24393/15 "2019-05-11T14:42:05Z")

</div>

A couple of other nitpicks for consideration:

- Why is `SigningMode` a struct? Should it not be an enum with three cases? Maybe it should only have two cases, `data` and `custom`, as the file case is only a _very_ thin wrapper of straightforward `Data(contentsOf:)` logic.
- I'm not sure `BasicNotification` holds it weight. Almost every notification sent nowadays requires some amount of custom associated data. I think providing the `APNSNotification` protocol only and asking clients to conform to it is practical and cuts down on API surface area. The `BasicNotification` is really only useful for a demo snippet.

---

<div class="post-metadata">

**Author:** ![kylebrowning](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/kylebrowning/32/9837_2.png) [@kylebrowning](https://forums.swift.org/u/kylebrowning)\
**Post date:** [May 11, 2019, 3:39pm UTC](https://forums.swift.org/t/feedback-nioapns-nio-based-apple-push-notification-service/24393/16 "2019-05-11T15:39:02Z")

</div>

OKay [heres a PR with all the changes](https://github.com/kylebrowning/swift-nio-apns/pull/21) @bzamayo.

I elected to keep the File case because it makes development a lot easier for the engineer.

One thing Im not sure on. There is no way to encode just a single property to a certain value. Id have to write the encoding code for every property which seems overkill.

What I've done is made the initializer interface be a boolean, but the stored property is an Int.

Apple also defines the value as a Number in their documentation so Im okay with the underlying property being an Integer.

---

<div class="post-metadata">

**Author:** ![bzamayo](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/bzamayo/32/764_2.png) [@bzamayo](https://forums.swift.org/u/bzamayo)\
**Post date:** [May 11, 2019, 4:35pm UTC](https://forums.swift.org/t/feedback-nioapns-nio-based-apple-push-notification-service/24393/17 "2019-05-11T16:35:20Z")

</div>

Yeah, there's no easy way of overriding just a couple of parameters without implementing `encode(to:)` and losing all automatic synthesis. I think your compromise is fine.

Thanks for working on this. It looks great and I'm definitely going to use it in the future.

---

<div class="post-metadata">

**Author:** ![kylebrowning](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/kylebrowning/32/9837_2.png) [@kylebrowning](https://forums.swift.org/u/kylebrowning)\
**Post date:** [May 11, 2019, 4:40pm UTC](https://forums.swift.org/t/feedback-nioapns-nio-based-apple-push-notification-service/24393/18 "2019-05-11T16:40:28Z")

</div>

Cool, merged!

---

<div class="post-metadata">

**Author:** ![johannesweiss](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/johannesweiss/32/38183_2.png) [@johannesweiss](https://forums.swift.org/u/johannesweiss)\
**Post date:** [May 16, 2019, 3:40pm UTC](https://forums.swift.org/t/feedback-nioapns-nio-based-apple-push-notification-service/24393/19 "2019-05-16T15:40:44Z")

</div>

Thanks @kylebrowning, this looks really good. I just have feedback regarding the types left, this is mostly expanding a few points from my [previous feedback](https://forums.swift.org/t/discussion-nioapns-nio-based-apple-push-notification-service/23384/7).

## `ByteBuffer` as the buffer type

This package uses `Data` as the data type for buffers everywhere. I totally think we should support `Data` but we should also support `ByteBuffer`. In the NIO ecosystem, you most likely already have `ByteBuffer`s, now if you use this package, you'd go `ByteBuffer -> Data -> ByteBuffer` to actually write it to the wire. So we have two unnecessary conversions here.

I think all types should be changed to use `ByteBuffer` as the main type and have convenience functions that allow the users to use `Data` too. That would make nothing slower but will make everything that uses `ByteBuffer` (which is what you get from the network) massively faster.

## Top-level types

I think we have too many top-level types here. This is a (hopefully) complete list of the types we have:

### `NIOAPNS` module

- `public struct APNSConfiguration`

- `public final class APNSConnection`

- `public enum APNSErrors`

- `public enum APNSResponseError`

why do we need this? This should be part of or nested inside of `APNSErrors`

- `public enum APNSTokenError`

why do we need this? This should be part of or nested inside of `APNSErrors`

- `public struct APNSError`

why do we have this? This should be part of or nested inside of `APNSErrors`

- `public enum APNSSoundType`

Couldn't this be nested in `APNSNotification`?

- `public protocol APNSNotification`

- `public struct APNSSoundDictionary`

this one too?

- `public struct APSPayload`

- `public struct Alert`

This name is way to general, we should nest this into something too.

- `public struct APNSRequestContext`

what does this do, does it really need to be a top-level type?

### `NIOAPNSJWT` module

- `public enum APNSSignatureError`

Why is this in the `NIOAPNSJWT` module?

- `public class DataSigner`

can we nest this in a `enum APNSSigners {}`?

- `public class FileSigner`

this one too?

- `public struct JWT`

- `public protocol APNSSigner`

Why is this in the `JWT` module?

- `public enum SigningMode`

I think we should also nest this into something

---

<div class="post-metadata">

**Author:** ![kylebrowning](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/kylebrowning/32/9837_2.png) [@kylebrowning](https://forums.swift.org/u/kylebrowning)\
**Post date:** [May 16, 2019, 8:31pm UTC](https://forums.swift.org/t/feedback-nioapns-nio-based-apple-push-notification-service/24393/20 "2019-05-16T20:31:23Z")

</div>

Ive done the namespace changes [here](https://github.com/kylebrowning/swift-nio-apns/pull/22).

Will work on ByteBuffer after we shore up the namespace.

[Next page](https://forums.swift.org/t/feedback-nioapns-nio-based-apple-push-notification-service/24393.md?page=2)
