Module: Perfect-Notifications
enum IOSNotificationItem
Example code:

// BEGIN one-time initialization code

let configurationName = "My configuration name - can be whatever"

NotificationPusher.addConfigurationIOS(configurationName) {
(net:NetTCPSSL) in

// This code will be called whenever a new connection to the APNS service is required.
// Configure the SSL related settings.

net.keyFilePassword = "if you have password protected key file"

guard net.useCertificateChainFile("path/to/entrust_2048_ca.cer") &&
net.useCertificateFile("path/to/aps_development.pem") &&
net.usePrivateKeyFile("path/to/key.pem") &&
net.checkPrivateKey() else {

let code = Int32(net.errorCode())
print("Error validating private key file: \(net.errorStr(code))")
return
}
}

NotificationPusher.development = true // set to toggle to the APNS sandbox server

// END one-time initialization code

// BEGIN - individual notification push

let deviceId = "hex string device id"
let ary = [IOSNotificationItem.AlertBody("This is the message"), IOSNotificationItem.Sound("default")]
let n = NotificationPusher()

n.apnsTopic = "com.company.my-app"

n.pushIOS(configurationName, deviceToken: deviceId, expiration: 0, priority: 10, notificationItems: ary) {
response in

print("NotificationResponse: \(response.code) \(response.body)")
}

// END - individual notification push
case alertBody(String)
alert body child property
case alertTitle(String)
alert title child property
case alertActionLoc(String)
alert action-loc-key
case badge(Int)
aps badge key
case sound(String)
aps sound key
case contentAvailable
aps content-available key
case category(String)
aps category key
struct NotificationResponse
The response object given after a push attempt.
var status: HTTPResponseStatus
The response code for the request.
var body: [UInt8]
The response body data bytes.
var jsonObjectBody: [String:Any]
The body data bytes interpreted as JSON and decoded into a Dictionary.
var stringBody: String
The body data bytes converted to String.
class NotificationPusher
The interface for APNS notifications.
static var development = false
Toggle development or production on a global basis.
typealias typealias netConfigurator = (NetTCPSSL) -> ()
On-demand configuration for SSL related functions.
var apnsTopic: String?
Sets the apns-topic which will be used for iOS notifications.
static func func addConfigurationIOS(name nam: String, configurator: @escaping netConfigurator)
Add a configuration given a name and a callback.
A particular configuration will generally correspond to an individual app.
The configuration callback will be called each time a new connection is initiated to the APNS.
Within the callback you will want to set:
1. Path to chain file as provided by Apple: net.useCertificateChainFile("path/to/entrust_2048_ca.cer")
2. Path to push notification certificate as obtained from Apple: net.useCertificateFile("path/to/aps.pem")
3a. Password for the certificate's private key file, if it is password protected: net.keyFilePassword = "password"
3b. Path to the certificate's private key file: net.usePrivateKeyFile("path/to/key.pem")
func init()
Public initializer
func init(apnsTopic: String)
Initialize given iOS apns-topic string.
This can be set after initialization on the X.apnsTopic property.
func pushIOS(configurationName: String, deviceToken: String, expiration: UInt32, priority: UInt8, notificationItems: [IOSNotificationItem], callback: @escaping (NotificationResponse) -> ())
Push one message to one device.
Provide the previously set configuration name, device token.
Provide the expiration and priority as described here:
https://developer.apple.com/library/mac/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/Chapters/APNsProviderAPI.html
Provide a list of IOSNotificationItems.
Provide a callback with which to receive the response.
func pushIOS(configurationName: String, deviceTokens: [String], expiration: UInt32, priority: UInt8, notificationItems: [IOSNotificationItem], callback: @escaping ([NotificationResponse]) -> ())
Push one message to multiple devices.
Provide the previously set configuration name, and zero or more device tokens. The same message will be sent to each device.
Provide the expiration and priority as described here:
https://developer.apple.com/library/mac/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/Chapters/APNsProviderAPI.html
Provide a list of IOSNotificationItems.
Provide a callback with which to receive the responses.