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