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.
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)
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))
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)
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
}
}
link |
Stars: 1 |
Last commit: 2 weeks ago |
Refactoring and improvements. New token now generates only after hour.
Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics