Random messages
This commit is contained in:
parent
c19bc3c299
commit
ec309e77db
@ -8,7 +8,9 @@ struct APNSInterface {
|
||||
private struct Payload: Codable {}
|
||||
|
||||
private var apnsConfiguration: APNSClientConfiguration!
|
||||
private var apnsNotification: APNSAlertNotification<Payload>!
|
||||
private let title: String
|
||||
private let messages: [String]
|
||||
private let topic: String
|
||||
private let apnsEventGroup = MultiThreadedEventLoopGroup(numberOfThreads: System.coreCount)
|
||||
private let apnsRequestEncoder = JSONEncoder()
|
||||
private let apnsResponseDecoder = JSONDecoder()
|
||||
@ -26,18 +28,9 @@ struct APNSInterface {
|
||||
apnsConfiguration = APNSClientConfiguration(
|
||||
authenticationMethod: authentication,
|
||||
environment: .sandbox)
|
||||
|
||||
let alert = APNSAlertNotificationContent(
|
||||
title: .raw(config.messageTitle),
|
||||
body: .raw(config.messageBody))
|
||||
|
||||
apnsNotification = APNSAlertNotification(
|
||||
alert: alert,
|
||||
expiration: .none,
|
||||
priority: .immediately,
|
||||
topic: config.topic,
|
||||
payload: Payload(),
|
||||
sound: .default)
|
||||
title = config.messageTitle
|
||||
messages = config.messages
|
||||
topic = config.topic
|
||||
}
|
||||
|
||||
func sendPush(to tokens: Set<String>) async {
|
||||
@ -47,6 +40,17 @@ struct APNSInterface {
|
||||
responseDecoder: apnsResponseDecoder,
|
||||
requestEncoder: apnsRequestEncoder)
|
||||
log(info: "Client created")
|
||||
let alert = APNSAlertNotificationContent(
|
||||
title: .raw(title),
|
||||
body: .raw(messages.randomElement()!))
|
||||
|
||||
let apnsNotification = APNSAlertNotification(
|
||||
alert: alert,
|
||||
expiration: .none,
|
||||
priority: .immediately,
|
||||
topic: topic,
|
||||
payload: Payload(),
|
||||
sound: .default)
|
||||
do {
|
||||
for token in tokenStorage.tokens {
|
||||
log(info: "Sending push to \(token.prefix(6))...")
|
||||
|
@ -16,7 +16,7 @@ struct ServerConfiguration: Codable {
|
||||
|
||||
let messageTitle: String
|
||||
|
||||
let messageBody: String
|
||||
let messages: [String]
|
||||
|
||||
let buttonPin: Int
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user