Sure @tachyonics. An example now exists in main.swift.
Thats the simplest implementation. The reason I didn't include larger usage directive is because this library API might change based on community input.
The short explanation is you would import NIOAPNS, create an alert, open a connection, and send the request with your push notification.
In an example like Vapor, this would most likely be a service.
From there, your Vapor app can infer when to open connections to APNS, and which devices to send to the push notifications too.
To elaborate a bit further(maybe this isn't needed but Ill continue) I see it happening like this.
- iOS app registers device for remote notifications
- iOS app gets a device token from Apple
- iOS app sends POST request with said token to a Vapor API
- Vapor stores device token.
- Later at some slotted time/event, for example when a new post is created, you open a connection to APNS, and send a request for each registered device.
Vapor would handle storing the device tokens via Fluent into the database of choice, and create these connections as needed, and asynchronously send the requests as needed. It's really up to how someone is trying to use APNS.
A good example is a pub sub model that something like PubNub (and others) use. You subscribe to a channel, say cats, and when you subscribe its tied to your registered device token. Something happens with cats and you want to notify everyone on that channel cats that some cat has been added, or maybe some cat spent a life.
This library consolidates, and uses the newest tech for Service Side Swift, in a way that requires no other dependencies. It does it with the same approach that NIO takes when building HTTP clients so that it is event-driven for high performance and non-blocking.
The main reason this is complicated is the advent of http2, Swift NIO http2 and JWT/ES256 encryption, incorporating all that for cross platform completeness, and near zero dependency(OpenSSL).
If this isn't wha you're asking I can make another stab at it in the morning.
Id be happy to explain the nuances of the APNS, but most of it can be read here and here.