|
| 1 | +//===----------------------------------------------------------------------===// |
| 2 | +// |
| 3 | +// This source file is part of the APNSwift open source project |
| 4 | +// |
| 5 | +// Copyright (c) 2022 the APNSwift project authors |
| 6 | +// Licensed under Apache License v2.0 |
| 7 | +// |
| 8 | +// See LICENSE.txt for license information |
| 9 | +// See CONTRIBUTORS.txt for the list of APNSwift project authors |
| 10 | +// |
| 11 | +// SPDX-License-Identifier: Apache-2.0 |
| 12 | +// |
| 13 | +//===----------------------------------------------------------------------===// |
| 14 | + |
| 15 | +import struct Foundation.UUID |
| 16 | + |
| 17 | +/// A Push to Talk (PTT) notification. |
| 18 | +public struct APNSPushToTalkNotification<Payload: Encodable & Sendable>: APNSMessage { |
| 19 | + /// A canonical UUID that identifies the notification. If there is an error sending the notification, |
| 20 | + /// APNs uses this value to identify the notification to your server. The canonical form is 32 lowercase hexadecimal digits, |
| 21 | + /// displayed in five groups separated by hyphens in the form 8-4-4-4-12. An example UUID is as follows: |
| 22 | + /// `123e4567-e89b-12d3-a456-42665544000`. |
| 23 | + /// |
| 24 | + /// If you omit this, a new UUID is created by APNs and returned in the response. |
| 25 | + public var apnsID: UUID? |
| 26 | + |
| 27 | + /// The topic for the notification. In general, the topic is your app’s bundle ID/app ID suffixed with `.voip-ptt`. |
| 28 | + public var topic: String |
| 29 | + |
| 30 | + /// The date when the notification is no longer valid and can be discarded. If this value is not `none`, |
| 31 | + /// APNs stores the notification and tries to deliver it at least once, |
| 32 | + /// repeating the attempt as needed if it is unable to deliver the notification the first time. |
| 33 | + /// If the value is `immediately`, APNs treats the notification as if it expires immediately |
| 34 | + /// and does not store the notification or attempt to redeliver it. |
| 35 | + public var expiration: APNSNotificationExpiration |
| 36 | + |
| 37 | + /// The priority of the notification. |
| 38 | + public var priority: APNSPriority |
| 39 | + |
| 40 | + /// Your custom payload. |
| 41 | + public var payload: Payload |
| 42 | + |
| 43 | + /// Initializes a new ``APNSPushToTalkNotification``. |
| 44 | + /// |
| 45 | + /// - Important: Your dynamic payload will get encoded to the root of the JSON payload that is send to APNs. |
| 46 | + /// It is **important** that you do not encode anything with the key `aps` |
| 47 | + /// |
| 48 | + /// - Parameters: |
| 49 | + /// - expiration: The date when the notification is no longer valid and can be discarded. Defaults to `.immediately` |
| 50 | + /// - priority: The priority of the notification. Defaults to `.immediately` |
| 51 | + /// - appID: Your app’s bundle ID/app ID. This will be suffixed with `.voip-ptt`. |
| 52 | + /// - payload: Payload contain speaker data like name of active speaker or indication the session has ended. |
| 53 | + /// - apnsID: A canonical UUID that identifies the notification. |
| 54 | + @inlinable |
| 55 | + public init( |
| 56 | + expiration: APNSNotificationExpiration = .immediately, |
| 57 | + priority: APNSPriority = .immediately, |
| 58 | + appID: String, |
| 59 | + payload: Payload, |
| 60 | + apnsID: UUID? = nil |
| 61 | + ) { |
| 62 | + self.init( |
| 63 | + expiration: expiration, |
| 64 | + priority: priority, |
| 65 | + topic: appID + ".voip-ptt", |
| 66 | + payload: payload, |
| 67 | + apnsID: apnsID |
| 68 | + ) |
| 69 | + } |
| 70 | + |
| 71 | + /// Initializes a new ``APNSPushToTalkNotification``. |
| 72 | + /// |
| 73 | + /// - Important: Your dynamic payload will get encoded to the root of the JSON payload that is send to APNs. |
| 74 | + /// It is **important** that you do not encode anything with the key `aps` |
| 75 | + /// |
| 76 | + /// - Parameters: |
| 77 | + /// - expiration: The date when the notification is no longer valid and can be discarded. Defaults to `.immediately` |
| 78 | + /// - priority: The priority of the notification. Defaults to `.immediately` |
| 79 | + /// - topic: The topic for the notification. In general, the topic is your app’s bundle ID/app ID suffixed with `.voip-ptt`. |
| 80 | + /// - payload: Payload contain speaker data like name of active speaker or indication the session has ended. |
| 81 | + /// - apnsID: A canonical UUID that identifies the notification. |
| 82 | + @inlinable |
| 83 | + public init( |
| 84 | + expiration: APNSNotificationExpiration = .immediately, |
| 85 | + priority: APNSPriority = .immediately, |
| 86 | + topic: String, |
| 87 | + payload: Payload, |
| 88 | + apnsID: UUID? = nil |
| 89 | + ) { |
| 90 | + self.expiration = expiration |
| 91 | + self.priority = priority |
| 92 | + self.topic = topic |
| 93 | + self.payload = payload |
| 94 | + self.apnsID = apnsID |
| 95 | + } |
| 96 | +} |
| 97 | + |
| 98 | +extension APNSPushToTalkNotification where Payload == EmptyPayload { |
| 99 | + /// Initializes a new ``APNSPushToTalkNotification`` with an EmptyPayload. |
| 100 | + /// |
| 101 | + /// - Important: Your dynamic payload will get encoded to the root of the JSON payload that is send to APNs. |
| 102 | + /// It is **important** that you do not encode anything with the key `aps` |
| 103 | + /// |
| 104 | + /// - Parameters: |
| 105 | + /// - expiration: The date when the notification is no longer valid and can be discarded. Defaults to `.immediately` |
| 106 | + /// - priority: The priority of the notification. Defaults to `.immediately` |
| 107 | + /// - appID: Your app’s bundle ID/app ID. This will be suffixed with `.voip-ptt`. |
| 108 | + /// - payload: Empty Payload. |
| 109 | + /// - apnsID: A canonical UUID that identifies the notification. |
| 110 | + public init( |
| 111 | + expiration: APNSNotificationExpiration = .immediately, |
| 112 | + priority: APNSPriority = .immediately, |
| 113 | + appID: String, |
| 114 | + apnsID: UUID? = nil |
| 115 | + ) { |
| 116 | + self.init( |
| 117 | + expiration: expiration, |
| 118 | + priority: priority, |
| 119 | + topic: appID + ".voip-ptt", |
| 120 | + payload: EmptyPayload(), |
| 121 | + apnsID: apnsID |
| 122 | + ) |
| 123 | + } |
| 124 | +} |
0 commit comments