@@ -23,15 +23,15 @@ public protocol APNSwiftNotification: Encodable {
2323
2424/// This structure provides the data structure for an APNS Payload
2525public struct APNSwiftPayload : Encodable {
26- public let alert : APNSwiftAlert ?
26+ public let alert : APNSwift . APNSwiftAlert ?
2727 public let badge : Int ?
28- public let sound : APNSwiftSoundType ?
28+ public let sound : APNSwift . APNSwiftSoundType ?
2929 public let contentAvailable : Int ?
3030 public let mutableContent : Int ?
3131 public let category : String ?
3232 public let threadID : String ?
3333
34- public init ( alert: APNSwiftAlert ? = nil , badge: Int ? = nil , sound: APNSwiftSoundType ? = nil , hasContentAvailable: Bool = false , hasMutableContent: Bool = false , category: String ? = nil , threadID: String ? = nil ) {
34+ public init ( alert: APNSwift . APNSwiftAlert ? = nil , badge: Int ? = nil , sound: APNSwift . APNSwiftSoundType ? = nil , hasContentAvailable: Bool = false , hasMutableContent: Bool = false , category: String ? = nil , threadID: String ? = nil ) {
3535 self . alert = alert
3636 self . badge = badge
3737 self . sound = sound
@@ -50,112 +50,4 @@ public struct APNSwiftPayload: Encodable {
5050 case category
5151 case threadID = " thread-id "
5252 }
53- /// This structure provides the data structure for an APNS Alert
54- public struct APNSwiftAlert : Codable {
55- public let title : String ?
56- public let subtitle : String ?
57- public let body : String ?
58- public let titleLocKey : String ?
59- public let titleLocArgs : [ String ] ?
60- public let actionLocKey : String ?
61- public let locKey : String ?
62- public let locArgs : [ String ] ?
63- public let launchImage : String ?
64-
65- /**
66- This structure provides the data structure for an APNS Alert
67- - Parameter title: The title to be displayed to the user.
68- - Parameter subtitle: The subtitle to be displayed to the user.
69- - Parameter body: The body of the push notification.
70- - Parameter titleLocKey: The key to a title string in the Localizable.strings file for the current
71- localization.
72- - Parameter titleLocArgs: Variable string values to appear in place of the format specifiers in
73- title-loc-key.
74- - Parameter actionLocKey: The string is used as a key to get a localized string in the current localization
75- to use for the right button’s title instead of “View”.
76- - Parameter locKey: A key to an alert-message string in a Localizable.strings file for the current
77- localization (which is set by the user’s language preference).
78- - Parameter locArgs: Variable string values to appear in place of the format specifiers in loc-key.
79- - Parameter launchImage: The filename of an image file in the app bundle, with or without the filename
80- extension.
81-
82- For more information see:
83- [Payload Key Reference](https://developer.apple.com/library/archive/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/PayloadKeyReference.html#)
84- ### Usage Example: ###
85- ````
86- let alert = Alert(title: "Hey There", subtitle: "Subtitle", body: "Body")
87- ````
88- */
89- public init ( title: String ? = nil , subtitle: String ? = nil , body: String ? = nil ,
90- titleLocKey: String ? = nil , titleLocArgs: [ String ] ? = nil , actionLocKey: String ? = nil ,
91- locKey: String ? = nil , locArgs: [ String ] ? = nil , launchImage: String ? = nil ) {
92- self . title = title
93- self . subtitle = subtitle
94- self . body = body
95- self . titleLocKey = titleLocKey
96- self . titleLocArgs = titleLocArgs
97- self . actionLocKey = actionLocKey
98- self . locKey = locKey
99- self . locArgs = locArgs
100- self . launchImage = launchImage
101- }
102-
103- enum CodingKeys : String , CodingKey {
104- case title
105- case subtitle
106- case body
107- case titleLocKey = " title-loc-key "
108- case titleLocArgs = " title-loc-args "
109- case actionLocKey = " action-loc-key "
110- case locKey = " loc-key "
111- case locArgs = " loc-args "
112- case launchImage = " launch-image "
113- }
114- }
115- public struct APNSSoundDictionary : Encodable {
116- public let critical : Int
117- public let name : String
118- public let volume : Double
119-
120- /**
121- Initialize an APNSSoundDictionary
122- - Parameter critical: The critical alert flag. Set to true to enable the critical alert.
123- - Parameter sound: The apps path to a sound file.
124- - Parameter volume: The volume for the critical alert’s sound. Set this to a value between 0.0 (silent) and 1.0 (full volume).
125-
126- For more information see:
127- [Payload Key Reference](https://developer.apple.com/library/archive/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/PayloadKeyReference.html#)
128- ### Usage Example: ###
129- ````
130- let apsSound = APNSSoundDictionary(isCritical: true, name: "cow.wav", volume: 0.8)
131- let aps = APNSwiftPayload(alert: alert, badge: 1, sound: .dictionary(apsSound))
132- ````
133- */
134- public init ( isCritical: Bool , name: String , volume: Double ) {
135- self . critical = isCritical ? 1 : 0
136- self . name = name
137- self . volume = volume
138- }
139- }
140- /**
141- An enum to define how to use sound.
142- - Parameter string: use this for a normal alert sound
143- - Parameter critical: use for a critical alert type
144- */
145- public enum APNSwiftSoundType : Encodable {
146- case normal( String )
147- case critical( APNSSoundDictionary )
148- }
149- }
150-
151- extension APNSwiftPayload . APNSwiftSoundType {
152- public func encode( to encoder: Encoder ) throws {
153- var container = encoder. singleValueContainer ( )
154- switch self {
155- case . normal( let string) :
156- try container. encode ( string)
157- case . critical( let dict) :
158- try container. encode ( dict)
159- }
160- }
16153}
0 commit comments