Skip to content

Commit 48e77d4

Browse files
authored
Merge pull request #92 from kylebrowning/tn-concise-naming
Make APNSwiftPayload naming more concise
2 parents e304056 + e22042b commit 48e77d4

File tree

11 files changed

+251
-173
lines changed

11 files changed

+251
-173
lines changed

README.md

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -82,19 +82,19 @@ let apnsConfig = ...
8282
let apns = try APNSwiftConnection.connect(configuration: apnsConfig, on: group.next()).wait()
8383
```
8484

85-
### Alert
85+
### APNSwiftAlert
8686

87-
[`Alert`](https://github.com/kylebrowning/swift-nio-http2-apns/blob/master/Sources/APNSwift/APNSRequest.swift) is the actual meta data of the push notification alert someone wishes to send. More details on the specifics of each property are provided [here](https://developer.apple.com/library/archive/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/PayloadKeyReference.html). They follow a 1-1 naming scheme listed in Apple's documentation
87+
[`APNSwiftAlert`](https://github.com/kylebrowning/APNSwift/blob/tn-concise-naming/Sources/APNSwift/APNSwiftAlert.swift) is the actual meta data of the push notification alert someone wishes to send. More details on the specifics of each property are provided [here](https://developer.apple.com/library/archive/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/PayloadKeyReference.html). They follow a 1-1 naming scheme listed in Apple's documentation
8888

8989

90-
#### Example `Alert`
90+
#### Example `APNSwiftAlert`
9191
```swift
92-
let alert = Alert(title: "Hey There", subtitle: "Full moon sighting", body: "There was a full moon last night did you see it")
92+
let alert = APNSwiftAlert(title: "Hey There", subtitle: "Full moon sighting", body: "There was a full moon last night did you see it")
9393
```
9494

9595
### APNSwiftPayload
9696

97-
[`APNSwiftPayload`](https://github.com/kylebrowning/APNSwift/blob/master/Sources/APNSwift/APNSwiftRequest.swift#L25) is the meta data of the push notification. Things like the alert, badge count. More details on the specifics of each property are provided [here](https://developer.apple.com/library/archive/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/PayloadKeyReference.html). They follow a 1-1 naming scheme listed in Apple's documentation
97+
[`APNSwiftPayload`](https://github.com/kylebrowning/APNSwift/blob/tn-concise-naming/Sources/APNSwift/APNSwiftPayload.swift) is the meta data of the push notification. Things like the alert, badge count. More details on the specifics of each property are provided [here](https://developer.apple.com/library/archive/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/PayloadKeyReference.html). They follow a 1-1 naming scheme listed in Apple's documentation
9898

9999

100100
#### Example `APNSwiftPayload`
@@ -139,10 +139,13 @@ var apnsConfig = try APNSwiftConfiguration(
139139
)
140140
let apns = try APNSwiftConnection.connect(configuration: apnsConfig, on: group.next()).wait()
141141
```
142+
142143
### Need a completely custom arbtirary payload and dont like being typecast?
144+
143145
APNSwift provides the ability to send raw payloads. You can use `Data`, `ByteBuffer`, `DispatchData`, `Array`
144146
Though this is to be used with caution. APNSwift cannot gurantee delivery if you do not have the correct payload.
145147
For more information see: [Creating APN Payload](https://developer.apple.com/library/archive/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/CreatingtheNotificationPayload.html)
148+
146149
```swift
147150
let notificationJsonPayload = ...
148151
let data: Data = try! encoder.encode(notificationJsonPayload)
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// This source file is part of the APNSwift open source project
4+
//
5+
// Copyright (c) 2020 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+
/// This structure provides the data structure for an APNS Alert
16+
public struct APNSwiftAlert: Codable {
17+
public let title: String?
18+
public let subtitle: String?
19+
public let body: String?
20+
public let titleLocKey: String?
21+
public let titleLocArgs: [String]?
22+
public let actionLocKey: String?
23+
public let locKey: String?
24+
public let locArgs: [String]?
25+
public let launchImage: String?
26+
27+
/**
28+
This structure provides the data structure for an APNS Alert
29+
- Parameter title: The title to be displayed to the user.
30+
- Parameter subtitle: The subtitle to be displayed to the user.
31+
- Parameter body: The body of the push notification.
32+
- Parameter titleLocKey: The key to a title string in the Localizable.strings file for the current
33+
localization.
34+
- Parameter titleLocArgs: Variable string values to appear in place of the format specifiers in
35+
title-loc-key.
36+
- Parameter actionLocKey: The string is used as a key to get a localized string in the current localization
37+
to use for the right button’s title instead of “View”.
38+
- Parameter locKey: A key to an alert-message string in a Localizable.strings file for the current
39+
localization (which is set by the user’s language preference).
40+
- Parameter locArgs: Variable string values to appear in place of the format specifiers in loc-key.
41+
- Parameter launchImage: The filename of an image file in the app bundle, with or without the filename
42+
extension.
43+
44+
For more information see:
45+
[Payload Key Reference](https://developer.apple.com/library/archive/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/PayloadKeyReference.html#)
46+
### Usage Example: ###
47+
````
48+
let alert = Alert(title: "Hey There", subtitle: "Subtitle", body: "Body")
49+
````
50+
*/
51+
public init(title: String? = nil, subtitle: String? = nil, body: String? = nil,
52+
titleLocKey: String? = nil, titleLocArgs: [String]? = nil, actionLocKey: String? = nil,
53+
locKey: String? = nil, locArgs: [String]? = nil, launchImage: String? = nil) {
54+
self.title = title
55+
self.subtitle = subtitle
56+
self.body = body
57+
self.titleLocKey = titleLocKey
58+
self.titleLocArgs = titleLocArgs
59+
self.actionLocKey = actionLocKey
60+
self.locKey = locKey
61+
self.locArgs = locArgs
62+
self.launchImage = launchImage
63+
}
64+
65+
enum CodingKeys: String, CodingKey {
66+
case title
67+
case subtitle
68+
case body
69+
case titleLocKey = "title-loc-key"
70+
case titleLocArgs = "title-loc-args"
71+
case actionLocKey = "action-loc-key"
72+
case locKey = "loc-key"
73+
case locArgs = "loc-args"
74+
case launchImage = "launch-image"
75+
}
76+
}

Sources/APNSwift/APNSwiftClient.swift

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// This source file is part of the APNSwift open source project
4+
//
5+
// Copyright (c) 2019-2020 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+
115
import Foundation
216
import Logging
317
import NIO
@@ -37,7 +51,7 @@ extension APNSwiftClient {
3751
try apns.send(notification, pushType: .alert, to: "b27a07be2092c7fbb02ab5f62f3135c615e18acc0ddf39a30ffde34d41665276", with: JSONEncoder(), expiration: expiry, priority: 10, collapseIdentifier: "huro2").wait()
3852
```
3953
*/
40-
public func send(_ alert: APNSwiftPayload.APNSwiftAlert,
54+
public func send(_ alert: APNSwiftAlert,
4155
pushType: APNSwiftConnection.PushType = .alert,
4256
to deviceToken: String,
4357
with encoder: JSONEncoder = JSONEncoder(),
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// This source file is part of the APNSwift open source project
4+
//
5+
// Copyright (c) 2020 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+
/// This is a protocol which allows developers to construct their own Notification payload
16+
public protocol APNSwiftNotification: Encodable {
17+
var aps: APNSwiftPayload { get }
18+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// This source file is part of the APNSwift open source project
4+
//
5+
// Copyright (c) 2019-2020 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+
/// This structure provides the data structure for an APNS Payload
16+
public struct APNSwiftPayload: Encodable {
17+
public let alert: APNSwift.APNSwiftAlert?
18+
public let badge: Int?
19+
public let sound: APNSwift.APNSwiftSoundType?
20+
public let contentAvailable: Int?
21+
public let mutableContent: Int?
22+
public let category: String?
23+
public let threadID: String?
24+
25+
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) {
26+
self.alert = alert
27+
self.badge = badge
28+
self.sound = sound
29+
self.contentAvailable = hasContentAvailable ? 1 : 0
30+
self.mutableContent = hasMutableContent ? 1 : 0
31+
self.category = category
32+
self.threadID = threadID
33+
}
34+
35+
enum CodingKeys: String, CodingKey {
36+
case alert
37+
case badge
38+
case sound
39+
case contentAvailable = "content-available"
40+
case mutableContent = "mutable-content"
41+
case category
42+
case threadID = "thread-id"
43+
}
44+
}

Sources/APNSwift/APNSwiftRequest.swift

Lines changed: 0 additions & 161 deletions
This file was deleted.

0 commit comments

Comments
 (0)