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.6
HTTP/2 Apple Push Notification Service for Swift
⭐️ 8
🕓 1 year ago
iOS macOS
.package(url: "https://github.com/polyitan/SwiftyAPNS.git", from: "0.0.6")

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.

    do {
        let responce = try await provider.push(notification)
        // Push Notification was successfully sent
    } catch {
        // Push Notification failure
    }

More examples

License

MIT License

GitHub

link
Stars: 8
Last commit: 1 year ago
Advertisement: IndiePitcher.com - Cold Email Software for Startups

Release Notes

0.0.6
1 year ago

Migrated to new swift concurrency

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