diff --git a/Sources/App/APNSInterface.swift b/Sources/App/APNSInterface.swift index ce98c25..e6d494c 100644 --- a/Sources/App/APNSInterface.swift +++ b/Sources/App/APNSInterface.swift @@ -8,7 +8,9 @@ struct APNSInterface { private struct Payload: Codable {} private var apnsConfiguration: APNSClientConfiguration! - private var apnsNotification: APNSAlertNotification! + 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) 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))...") diff --git a/Sources/App/ServerConfiguration.swift b/Sources/App/ServerConfiguration.swift index f9a37cf..af2f02b 100644 --- a/Sources/App/ServerConfiguration.swift +++ b/Sources/App/ServerConfiguration.swift @@ -16,7 +16,7 @@ struct ServerConfiguration: Codable { let messageTitle: String - let messageBody: String + let messages: [String] let buttonPin: Int