The interface for APNS 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")
// 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