Swiftpack.co - polyitan/SwiftyAPNS as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by polyitan.
polyitan/SwiftyAPNS 0.0.5
HTTP/2 Apple Push Notification Service for Swift
⭐️ 1
🕓 2 weeks ago
iOS macOS
.package(url: "https://github.com/polyitan/SwiftyAPNS.git", from: "0.0.5")

SwiftyAPNS

HTTP/2 Apple Push Notification Service for Swift.

There are two ways how the provider server can communicate with the Apple Push Notification service (APNs). The framework is supported both token-based and certificate-based authentication, but the former is preferred.

JWT Token provider

Before sending any pushes need to instantiate the APNs provider. For provider with a token-based connection need to know Apple Developer Team ID (can be getting from the Account page) and Apple Push Notification Authentication Key.

let keyP8 = <#Apple Auth Key (.p8) content#>
let keyId = <#Apple Auth Key ID#>
let teamId = <#Apple Developer Team ID#>
let provider = APNSProvider.init(p8: keyP8, keyId: keyId, teamId: teamId)

Payload examples

Plain payload:

let plain = APNSPayload(alert: .plain(plain: "Plain notification."))

Localized payload:

var alert = APSLocalizedAlert()
alert.title = "Title"
alert.subtitle = "Subtitle"
alert.body = "Localized notification body."
let localized = APNSPayload(alert: .localized(alert: alert))

Notification example

To create Notification we need a DeviceToken, a Topic, and a Payload.

var options = APNSNotificationOptions.default
options.type = .alert
options.topic = <#Remote Notification Topic#
let notification = APNSNotification.init(payload: <#Notification Payload#>,
                                         token: <#Device Token#>,
                                         options: options)

Sending push notifications

The values in responses can be handled asynchronously.

provider.push(notification) { (result) in
    switch(result) {
    case .success(let responce):
        if let error = responce.reason {
            // Push Notification failure
        } else {
            // Push Notification was successfully sent
        }
    case .failure(let error):
        // Push Notification failure
    }
}

More examples

License

MIT License

GitHub

link
Stars: 1
Last commit: 2 weeks ago
jonrohan Something's broken? Yell at me @ptrpavlik. Praise and feedback (and money) is also welcome.

Release Notes

0.0.5
2 weeks ago

Refactoring and improvements. New token now generates only after hour.

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics