vapor / apns

Helpful extensions and abstractions for using APNSwift
MIT License
115 stars 29 forks source link

Use HTTP Client from vapor and update APNS library, add multiple configs #46

Closed kylebrowning closed 2 years ago

kylebrowning commented 2 years ago

This PR removes EventLoopFutures, and adds async / await capabilities

It also updates to use the last APNSwift update which under the hood uses a ASyncHTTPClient. Ive removed the unneeded protocols, and conformance in favor of passing in the client.

Multiple clients are now supported as well.

Its currently dependent on https://github.com/swift-server-community/APNSwift/pull/130 - Now merged

once this is merged I will put out an alpha major release for this repo as well

The new configuration interface is,

        let apnsConfig: APNSConfiguration = .init(
            authenticationConfig: authenticationConfig,
            topic: "MY_TOPIC",
            environment: .sandbox,
            eventLoopGroupProvider: .shared(app.eventLoopGroup),
            logger: app.logger
        )
        app.apns.containers.use(apnsConfig, as: .default)

You can also make a custom one if you'd like

extension APNSContainers.ID {
    static var custom: APNSContainers.ID {
        return .init(string: "custom")
    }
}
....
        let customConfig: APNSConfiguration = .init(
            authenticationConfig: authenticationConfig,
            topic: "MY_TOPIC_CUSTOM",
            environment: .production,
            eventLoopGroupProvider: .shared(app.eventLoopGroup),
            logger: app.logger
        )

        app.apns.containers.use(customConfig, as: .custom)

        app.get("test-push2") { req -> HTTPStatus in
            req.apns.client(.custom).send(....
        }