Skip to content

Commit a53fce2

Browse files
authored
Fix DocC and remove warnings (#210)
1 parent 9b5032e commit a53fce2

File tree

7 files changed

+53
-105
lines changed

7 files changed

+53
-105
lines changed

Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,5 +74,5 @@ let package = Package(
7474
]
7575
),
7676
],
77-
swiftLanguageVersions: [.v6]
77+
swiftLanguageModes: [.v6]
7878
)

README.md

Lines changed: 33 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[![sswg:graduated|94x20](https://img.shields.io/badge/sswg-graduated-green.svg)]([https://github.com/swift-server/sswg/blob/master/process/incubation.md#sandbox-level](https://www.swift.org/sswg/incubation-process.html#graduation-requirements))
22
[![Build](https://github.com/kylebrowning/APNSwift/workflows/test/badge.svg)](https://github.com/kylebrowning/APNSwift/actions)
3-
[![Documentation](https://img.shields.io/badge/documentation-blueviolet.svg)](https://swiftpackageindex.com/swift-server-community/APNSwift/main/documentation/apnswift)
3+
[![Documentation](https://img.shields.io/badge/documentation-blueviolet.svg)](https://swiftpackageindex.com/swift-server-community/APNSwift/documentation)
44
[![](https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2Fswift-server-community%2FAPNSwift%2Fbadge%3Ftype%3Dswift-versions)](https://swiftpackageindex.com/swift-server-community/APNSwift)
55
[![](https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2Fswift-server-community%2FAPNSwift%2Fbadge%3Ftype%3Dplatforms)](https://swiftpackageindex.com/swift-server-community/APNSwift)
66
<h1> APNSwift</h1>
@@ -25,7 +25,7 @@ To install `APNSwift`, just add the package as a dependency in your [**Package.s
2525

2626
```swift
2727
dependencies: [
28-
.package(url: "https://github.com/swift-server-community/APNSwift.git", from: "5.0.0"),
28+
.package(url: "https://github.com/swift-server-community/APNSwift.git", from: "6.0.0"),
2929
]
3030
```
3131

@@ -44,15 +44,11 @@ let client = APNSClient(
4444
),
4545
eventLoopGroupProvider: .createNew,
4646
responseDecoder: JSONDecoder(),
47-
requestEncoder: JSONEncoder(),
48-
byteBufferAllocator: .init(),
49-
backgroundActivityLogger: logger
47+
requestEncoder: JSONEncoder()
5048
)
51-
defer {
52-
client.shutdown { _ in
53-
logger.error("Failed to shutdown APNSClient")
54-
}
55-
}
49+
50+
// Shutdown the client when done
51+
try await client.shutdown()
5652
```
5753

5854
## Sending a simple notification
@@ -74,44 +70,40 @@ try await client.sendAlertNotification(
7470
topic: "com.app.bundle",
7571
payload: Payload()
7672
),
77-
deviceToken: "device-token",
78-
deadline: .nanoseconds(Int64.max),
79-
logger: myLogger
73+
deviceToken: "device-token"
8074
)
8175
```
8276

8377
## Sending Live Activity Update / End
84-
It requires sending `ContentState` matching with the live activity configuration to successfully update activity state. `ContentState` needs to conform to `Encodable`
78+
It requires sending `ContentState` matching with the live activity configuration to successfully update activity state. `ContentState` needs to conform to `Encodable` and `Sendable`.
8579

8680
```swift
87-
try await client.sendLiveActivityNotification(
88-
.init(
89-
expiration: .immediately,
90-
priority: .immediately,
91-
appID: "com.app.bundle",
92-
contentState: ContentState,
93-
event: .update,
94-
timestamp: Int(Date().timeIntervalSince1970)
95-
),
96-
activityPushToken: activityPushToken,
97-
deadline: .distantFuture
98-
)
81+
try await client.sendLiveActivityNotification(
82+
.init(
83+
expiration: .immediately,
84+
priority: .immediately,
85+
appID: "com.app.bundle",
86+
contentState: ContentState,
87+
event: .update,
88+
timestamp: Int(Date().timeIntervalSince1970)
89+
),
90+
deviceToken: activityPushToken
91+
)
9992
```
10093

10194
```swift
102-
try await client.sendLiveActivityNotification(
103-
.init(
104-
expiration: .immediately,
105-
priority: .immediately,
106-
appID: "com.app.bundle",
107-
contentState: ContentState,
108-
event: .end,
109-
timestamp: Int(Date().timeIntervalSince1970),
110-
dismissalDate: .dismissImmediately // Optional to alter default behaviour
111-
),
112-
activityPushToken: activityPushToken,
113-
deadline: .distantFuture
114-
)
95+
try await client.sendLiveActivityNotification(
96+
.init(
97+
expiration: .immediately,
98+
priority: .immediately,
99+
appID: "com.app.bundle",
100+
contentState: ContentState,
101+
event: .end,
102+
timestamp: Int(Date().timeIntervalSince1970),
103+
dismissalDate: .immediately // Optional to alter default behaviour
104+
),
105+
deviceToken: activityPushToken
106+
)
115107
```
116108
## Authentication
117109
`APNSwift` provides two authentication methods. `jwt`, and `TLS`.
@@ -121,8 +113,8 @@ These can be configured when created your `APNSClientConfiguration`
121113

122114
*Notes: `jwt` requires an encrypted version of your .p8 file from Apple which comes in a `pem` format. If you're having trouble with your key being invalid please confirm it is a PEM file*
123115
```
124-
openssl pkcs8 -nocrypt -in /path/to/my/key.p8 -out ~/Downloads/key.pem
125-
```
116+
openssl pkcs8 -nocrypt -in /path/to/my/key.p8 -out ~/Downloads/key.pem
117+
```
126118

127119
## Logging
128120
By default APNSwift has a no-op logger which will not log anything. However if you pass a logger in, you will see logs.

Sources/APNS/APNS.docc/APNSwift.md

Lines changed: 13 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,19 @@
1-
# ``APNSwift``
2-
A non-blocking Swift package for sending remote Apple Push Notification requests to Apple's APNS.
1+
# ``APNS``
2+
3+
A non-blocking Swift module for sending remote Apple Push Notification requests to APNS built on AsyncHttpClient.
34

45
## Installation
56

67
To install `APNSwift`, just add the package as a dependency in your [**Package.swift**](https://github.com/apple/swift-package-manager/blob/master/Documentation/PackageDescriptionV4.md#dependencies).
78

89
```swift
910
dependencies: [
10-
.package(url: "https://github.com/swift-server-community/APNSwift.git", from: "4.0.0"),
11+
.package(url: "https://github.com/swift-server-community/APNSwift.git", from: "6.0.0"),
1112
]
1213
```
13-
If youd like to give our bleeding edge release a try, which is what the Readme is expecting use `5.0.0-alpha.N`. If you need the old Readme, see [here](https://github.com/swift-server-community/APNSwift/tree/4.0.0)
14-
15-
```swift
16-
dependencies: [
17-
.package(url: "https://github.com/swift-server-community/APNSwift.git", from: "5.0.0-alpha.5"),
18-
]
19-
```
20-
21-
## Foundations
22-
`APNSwift` is built with a layered approach. It exposes three tiers of API's.
23-
1. A [raw API](https://github.com/swift-server-community/APNSwift/blob/d60241fe2b6eb193331567a871697d3f4bdf70fb/Sources/APNSwift/APNSClient.swift#L254) that takes basic types such as `String`'s
24-
2. A slightly more [semantically safe API](https://github.com/swift-server-community/APNSwift/blob/d60241fe2b6eb193331567a871697d3f4bdf70fb/Sources/APNSwift/APNSClient.swift#L183), which takes types, like [`APNSPriority`](https://github.com/swift-server-community/APNSwift/blob/main/Sources/APNSwift/APNSPriority.swift), [`APNSPushType`](https://github.com/swift-server-community/APNSwift/blob/main/Sources/APNSwift/APNSPushType.swift), [`APNSNotificationExpiration`](https://github.com/swift-server-community/APNSwift/blob/main/Sources/APNSwift/APNSNotificationExpiration.swift), etc.
25-
3. The [safest API](https://github.com/swift-server-community/APNSwift/blob/d60241fe2b6eb193331567a871697d3f4bdf70fb/Sources/APNSwift/Alert/APNSClient%2BAlert.swift#L32) which takes fully semantic types such as [`APNSAlertNotification`](https://github.com/swift-server-community/APNSwift/blob/d60241fe2b6eb193331567a871697d3f4bdf70fb/Sources/APNSwift/Alert/APNSAlertNotification.swift#L177)
26-
27-
**We recommened using number 3, the semantically safest API to ensure your push notification is delivered correctly**. *This README assumes that you are using number 3.* However if you need more granular approach, or something doesn't exist in this library, please use 2 or 1. (Also please open an issue if we missed something so we can get a semantically correct version!)
2814

2915
## Getting Started
30-
APNSwift aims to provide sementically correct structures to sending push notifications. You first need to setup a [`APNSClient`](https://github.com/swift-server-community/APNSwift/blob/main/Sources/APNSwift/APNSClient.swift). To do that youll need to know your authentication method
16+
APNSwift aims to provide semantically correct structures to sending push notifications. You first need to setup a [`APNSClient`](https://github.com/swift-server-community/APNSwift/blob/main/Sources/APNS/APNSClient.swift). To do that youll need to know your authentication method
3117

3218
```swift
3319
let client = APNSClient(
@@ -41,15 +27,11 @@ let client = APNSClient(
4127
),
4228
eventLoopGroupProvider: .createNew,
4329
responseDecoder: JSONDecoder(),
44-
requestEncoder: JSONEncoder(),
45-
byteBufferAllocator: .init(),
46-
backgroundActivityLogger: logger
30+
requestEncoder: JSONEncoder()
4731
)
48-
defer {
49-
client.shutdown { _ in
50-
logger.error("Failed to shutdown APNSClient")
51-
}
52-
}
32+
33+
// Shutdown the client when done
34+
try await client.shutdown()
5335
```
5436

5537
## Sending a simple notification
@@ -71,9 +53,7 @@ try await client.sendAlertNotification(
7153
topic: "com.app.bundle",
7254
payload: Payload()
7355
),
74-
deviceToken: "device-token",
75-
deadline: .nanoseconds(Int64.max),
76-
logger: myLogger
56+
deviceToken: "device-token"
7757
)
7858
```
7959

@@ -85,8 +65,8 @@ These can be configured when created your `APNSClientConfiguration`
8565

8666
*Notes: `jwt` requires an encrypted version of your .p8 file from Apple which comes in a `pem` format. If you're having trouble with your key being invalid please confirm it is a PEM file*
8767
```
88-
openssl pkcs8 -nocrypt -in /path/to/my/key.p8 -out ~/Downloads/key.pem
89-
```
68+
openssl pkcs8 -nocrypt -in /path/to/my/key.p8 -out ~/Downloads/key.pem
69+
```
9070

9171
## Logging
9272
By default APNSwift has a no-op logger which will not log anything. However if you pass a logger in, you will see logs.
@@ -98,31 +78,6 @@ This logger can be passed into the `APNSClient` and will log background things l
9878
#### **Notification Send Logger**
9979
This logger can be passed into any of the `send:` methods and will log everything related to a single send request.
10080

101-
## Using the non semantic safe APIs
102-
103-
APNSwift provides the ability to send raw payloads. You can use `Data`, `ByteBuffer`, `DispatchData`, `Array`
104-
Though this is to be used with caution. APNSwift cannot gurantee delivery if you do not have the correct payload.
105-
For more information see: [Creating APN Payload](https://developer.apple.com/library/archive/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/CreatingtheNotificationPayload.html)
106-
107-
```swift
108-
/// Extremely Raw,
109-
try await client.send(
110-
payload: payload,
111-
deviceToken: token,
112-
pushType: "alert", deadline: .distantFuture
113-
)
114-
115-
/// or a little safer but still raw
116-
try await client.send(
117-
payload: payload,
118-
deviceToken: token,
119-
pushType: .alert,
120-
expiration: .immediatly,
121-
priority: .immediatly,
122-
deadline: .distantFuture
123-
)
124-
```
125-
12681
## Server Example
12782
Take a look at [Program.swift](https://github.com/swift-server-community/APNSwift/blob/main/Sources/APNSwiftExample/Program.swift)
12883

@@ -136,3 +91,4 @@ Once inside configure your App Bundle ID and assign your development team. Build
13691

13792
* Pitch discussion: [Swift Server Forums](https://forums.swift.org/t/apple-push-notification-service-implementation-pitch/20193)
13893
* Proposal: [SSWG-0006](https://forums.swift.org/t/feedback-nioapns-nio-based-apple-push-notification-service/24393)
94+
* 5.0 breaking changings: [Swift Server Forums]([Blog post here on breaking changing](https://forums.swift.org/t/apnswift-5-0-0-beta-release/60075/3))

Sources/APNS/APNSClient.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ public final class APNSClient<Decoder: APNSJSONDecoder, Encoder: APNSJSONEncoder
5757

5858
/// Initializes a new APNS.
5959
///
60-
/// The client will create an internal ``HTTPClient`` which is used to make requests to APNs.
61-
/// This ``HTTPClient`` is intentionally internal since both authentication mechanisms are bound to a
60+
/// The client will create an internal `HTTPClient` which is used to make requests to APNs.
61+
/// This `HTTPClient` is intentionally internal since both authentication mechanisms are bound to a
6262
/// single connection and these connections cannot be shared.
6363
///
6464
///
@@ -67,7 +67,7 @@ public final class APNSClient<Decoder: APNSJSONDecoder, Encoder: APNSJSONEncoder
6767
/// - eventLoopGroupProvider: Specify how EventLoopGroup will be created.
6868
/// - responseDecoder: The decoder for the responses from APNs.
6969
/// - requestEncoder: The encoder for the requests to APNs.
70-
/// - backgroundActivityLogger: The logger used by the APNS.
70+
/// - byteBufferAllocator: The `ByteBufferAllocator`.
7171
public init(
7272
configuration: APNSClientConfiguration,
7373
eventLoopGroupProvider: NIOEventLoopGroupProvider,

Sources/APNS/APNSConfiguration.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public struct APNSClientConfiguration: Sendable {
6767
/// Upstream proxy, defaults to no proxy.
6868
public var proxy: HTTPClient.Configuration.Proxy?
6969

70-
/// Initializes a new ``APNSClient.Configuration``.
70+
/// Initializes a new ``APNSClientConfiguration``.
7171
///
7272
/// - Parameters:
7373
/// - authenticationMethod: The authentication method used by the ``APNSClient``.

Sources/APNS/Coding/APNSJSONDecoder.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import Foundation
1616
import NIOCore
1717
import NIOFoundationCompat
1818

19-
/// A protocol that is similar to the ``JSONDecoder``. This allows users of APNSwift to customize the decoder used
19+
/// A protocol that is similar to the `JSONDecoder`. This allows users of APNSwift to customize the decoder used
2020
/// for decoding the APNS response bodies.
2121
public protocol APNSJSONDecoder {
2222
func decode<T: Decodable>(_ type: T.Type, from buffer: ByteBuffer) throws -> T

Sources/APNS/Coding/APNSJSONEncoder.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import Foundation
1616
import NIOCore
1717
import NIOFoundationCompat
1818

19-
/// A protocol that is similar to the ``JSONEncoder``. This allows users of APNSwift to customize the encoder used
19+
/// A protocol that is similar to the `JSONEncoder`. This allows users of APNSwift to customize the encoder used
2020
/// for encoding the notification JSON payloads.
2121
public protocol APNSJSONEncoder {
2222
func encode<T: Encodable>(_ value: T, into buffer: inout ByteBuffer) throws

0 commit comments

Comments
 (0)