Skip to content

Commit aebf627

Browse files
committed
make naming more concise, avoid double namespacing
1 parent e304056 commit aebf627

File tree

8 files changed

+128
-118
lines changed

8 files changed

+128
-118
lines changed
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/// This structure provides the data structure for an APNS Alert
2+
public struct APNSwiftAlert: Codable {
3+
public let title: String?
4+
public let subtitle: String?
5+
public let body: String?
6+
public let titleLocKey: String?
7+
public let titleLocArgs: [String]?
8+
public let actionLocKey: String?
9+
public let locKey: String?
10+
public let locArgs: [String]?
11+
public let launchImage: String?
12+
13+
/**
14+
This structure provides the data structure for an APNS Alert
15+
- Parameter title: The title to be displayed to the user.
16+
- Parameter subtitle: The subtitle to be displayed to the user.
17+
- Parameter body: The body of the push notification.
18+
- Parameter titleLocKey: The key to a title string in the Localizable.strings file for the current
19+
localization.
20+
- Parameter titleLocArgs: Variable string values to appear in place of the format specifiers in
21+
title-loc-key.
22+
- Parameter actionLocKey: The string is used as a key to get a localized string in the current localization
23+
to use for the right button’s title instead of “View”.
24+
- Parameter locKey: A key to an alert-message string in a Localizable.strings file for the current
25+
localization (which is set by the user’s language preference).
26+
- Parameter locArgs: Variable string values to appear in place of the format specifiers in loc-key.
27+
- Parameter launchImage: The filename of an image file in the app bundle, with or without the filename
28+
extension.
29+
30+
For more information see:
31+
[Payload Key Reference](https://developer.apple.com/library/archive/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/PayloadKeyReference.html#)
32+
### Usage Example: ###
33+
````
34+
let alert = Alert(title: "Hey There", subtitle: "Subtitle", body: "Body")
35+
````
36+
*/
37+
public init(title: String? = nil, subtitle: String? = nil, body: String? = nil,
38+
titleLocKey: String? = nil, titleLocArgs: [String]? = nil, actionLocKey: String? = nil,
39+
locKey: String? = nil, locArgs: [String]? = nil, launchImage: String? = nil) {
40+
self.title = title
41+
self.subtitle = subtitle
42+
self.body = body
43+
self.titleLocKey = titleLocKey
44+
self.titleLocArgs = titleLocArgs
45+
self.actionLocKey = actionLocKey
46+
self.locKey = locKey
47+
self.locArgs = locArgs
48+
self.launchImage = launchImage
49+
}
50+
51+
enum CodingKeys: String, CodingKey {
52+
case title
53+
case subtitle
54+
case body
55+
case titleLocKey = "title-loc-key"
56+
case titleLocArgs = "title-loc-args"
57+
case actionLocKey = "action-loc-key"
58+
case locKey = "loc-key"
59+
case locArgs = "loc-args"
60+
case launchImage = "launch-image"
61+
}
62+
}

Sources/APNSwift/APNSwiftClient.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ extension APNSwiftClient {
3737
try apns.send(notification, pushType: .alert, to: "b27a07be2092c7fbb02ab5f62f3135c615e18acc0ddf39a30ffde34d41665276", with: JSONEncoder(), expiration: expiry, priority: 10, collapseIdentifier: "huro2").wait()
3838
```
3939
*/
40-
public func send(_ alert: APNSwiftPayload.APNSwiftAlert,
40+
public func send(_ alert: APNSwiftAlert,
4141
pushType: APNSwiftConnection.PushType = .alert,
4242
to deviceToken: String,
4343
with encoder: JSONEncoder = JSONEncoder(),

Sources/APNSwift/APNSwiftRequest.swift

Lines changed: 3 additions & 111 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,15 @@ public protocol APNSwiftNotification: Encodable {
2323

2424
/// This structure provides the data structure for an APNS Payload
2525
public 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
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
public struct APNSSoundDictionary: Encodable {
2+
public let critical: Int
3+
public let name: String
4+
public let volume: Double
5+
6+
/**
7+
Initialize an APNSSoundDictionary
8+
- Parameter critical: The critical alert flag. Set to true to enable the critical alert.
9+
- Parameter sound: The apps path to a sound file.
10+
- Parameter volume: The volume for the critical alert’s sound. Set this to a value between 0.0 (silent) and 1.0 (full volume).
11+
12+
For more information see:
13+
[Payload Key Reference](https://developer.apple.com/library/archive/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/PayloadKeyReference.html#)
14+
### Usage Example: ###
15+
````
16+
let apsSound = APNSSoundDictionary(isCritical: true, name: "cow.wav", volume: 0.8)
17+
let aps = APNSwiftPayload(alert: alert, badge: 1, sound: .dictionary(apsSound))
18+
````
19+
*/
20+
public init(isCritical: Bool, name: String, volume: Double) {
21+
self.critical = isCritical ? 1 : 0
22+
self.name = name
23+
self.volume = volume
24+
}
25+
}
26+
/**
27+
An enum to define how to use sound.
28+
- Parameter string: use this for a normal alert sound
29+
- Parameter critical: use for a critical alert type
30+
*/
31+
public enum APNSwiftSoundType: Encodable {
32+
case normal(String)
33+
case critical(APNSSoundDictionary)
34+
}
35+
36+
extension APNSwiftSoundType {
37+
public func encode(to encoder: Encoder) throws {
38+
var container = encoder.singleValueContainer()
39+
switch self {
40+
case .normal(let string):
41+
try container.encode(string)
42+
case .critical(let dict):
43+
try container.encode(dict)
44+
}
45+
}
46+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
extension APNSwiftPayload {
2+
@available(*, deprecated, renamed: "APNSwiftAlert")
3+
public typealias APNSwiftAlert = APNSwift.APNSwiftAlert
4+
5+
@available(*, deprecated, renamed: "APNSSoundDictionary")
6+
public typealias APNSSoundDictionary = APNSwift.APNSSoundDictionary
7+
8+
@available(*, deprecated, renamed: "APNSwiftSoundType")
9+
public typealias APNSwiftSoundType = APNSwift.APNSwiftSoundType
10+
}

Sources/APNSwiftExample/main.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ struct AcmeNotification: APNSwiftNotification {
5353
}
5454
}
5555

56-
let alert = APNSwiftPayload.APNSwiftAlert(title: "Hey There", subtitle: "Subtitle", body: "Body")
57-
let apsSound = APNSwiftPayload.APNSSoundDictionary(isCritical: true, name: "cow.wav", volume: 0.8)
56+
let alert = APNSwiftAlert(title: "Hey There", subtitle: "Subtitle", body: "Body")
57+
let apsSound = APNSSoundDictionary(isCritical: true, name: "cow.wav", volume: 0.8)
5858
let aps = APNSwiftPayload(alert: alert, badge: 0, sound: .critical(apsSound), hasContentAvailable: true)
5959
let temp = try! JSONEncoder().encode(aps)
6060
let string = String(bytes: temp, encoding: .utf8)

Sources/APNSwiftPemExample/main.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ struct AcmeNotification: APNSwiftNotification {
4747
}
4848
}
4949

50-
let alert = APNSwiftPayload.APNSwiftAlert(title: "Hey There", subtitle: "Subtitle", body: "Body")
51-
let apsSound = APNSwiftPayload.APNSSoundDictionary(isCritical: true, name: "cow.wav", volume: 0.8)
50+
let alert = APNSwiftAlert(title: "Hey There", subtitle: "Subtitle", body: "Body")
51+
let apsSound = APNSSoundDictionary(isCritical: true, name: "cow.wav", volume: 0.8)
5252
let aps = APNSwiftPayload(alert: alert, badge: 0, sound: .critical(apsSound), hasContentAvailable: true)
5353
let temp = try! JSONEncoder().encode(aps)
5454
let string = String(bytes: temp, encoding: .utf8)

Tests/APNSwiftTests/APNSwiftRequestTests.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import XCTest
2424
final class APNSwiftRequestTests: XCTestCase {
2525

2626
func testAlertEncoding() throws {
27-
let alert = APNSwiftPayload.APNSwiftAlert(title: "title", subtitle: "subtitle", body: "body", titleLocKey: "titlelockey",
27+
let alert = APNSwiftAlert(title: "title", subtitle: "subtitle", body: "body", titleLocKey: "titlelockey",
2828
titleLocArgs: ["titlelocarg1"], actionLocKey: "actionkey", locKey: "lockey", locArgs: ["locarg1"], launchImage: "launchImage")
2929

3030
let jsonData = try JSONEncoder().encode(alert)
@@ -63,7 +63,7 @@ final class APNSwiftRequestTests: XCTestCase {
6363
}
6464

6565
func testMinimalAlertEncoding() throws {
66-
let alert = APNSwiftPayload.APNSwiftAlert(title: "title", body: "body")
66+
let alert = APNSwiftAlert(title: "title", body: "body")
6767

6868
let jsonData = try JSONEncoder().encode(alert)
6969

0 commit comments

Comments
 (0)