You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
/// If you are configuring both a production and development container, ``production`` and ``development`` are also available.
6
+
///
7
+
/// - Note: You must configure this ID before using it by calling ``VaporAPNS/APNSContainers/use(_:eventLoopGroupProvider:responseDecoder:requestEncoder:byteBufferAllocator:as:isDefault:)``.
8
+
/// - Important: The actual default ID to use in ``Vapor/Application/APNS/client`` when none is provided is the first configuration that doesn't specify a value of `false` for `isDefault:`.
3
9
publicstaticvar`default`:APNSContainers.ID{
4
10
return.init(string:"default")
5
11
}
12
+
13
+
/// An ID that can be used for the production APNs environment.
14
+
///
15
+
/// - Note: You must configure this ID before using it by calling ``APNSContainers/use(_:eventLoopGroupProvider:responseDecoder:requestEncoder:byteBufferAllocator:as:isDefault:)``
16
+
publicstaticvarproduction:APNSContainers.ID{
17
+
return.init(string:"production")
18
+
}
19
+
20
+
/// An ID that can be used for the development (aka sandbox) APNs environment.
21
+
///
22
+
/// - Note: You must configure this ID before using it by calling ``APNSContainers/use(_:eventLoopGroupProvider:responseDecoder:requestEncoder:byteBufferAllocator:as:isDefault:)``
Copy file name to clipboardexpand all lines: Sources/VaporAPNS/APNSContainers.swift
+112-1
Original file line number
Diff line number
Diff line change
@@ -50,7 +50,118 @@ public final class APNSContainers: Sendable {
50
50
}
51
51
52
52
extensionAPNSContainers{
53
-
53
+
/// Configure APNs for a given container ID.
54
+
///
55
+
/// You must configure at lease one client in order to send notifications to devices. If you plan on supporting both development builds (ie. run from Xcode) and release builds (ie. TestFlight/App Store), you must configure at least two configurations:
56
+
///
57
+
/// ```swift
58
+
/// /// The .p8 file as a string.
59
+
/// let apnsKey = Environment.get("APNS_KEY_P8")
60
+
/// /// The identifier of the key in the developer portal.
61
+
/// let keyIdentifier = Environment.get("APNS_KEY_ID")
62
+
/// /// The team identifier of the app in the developer portal.
63
+
/// let teamIdentifier = Environment.get("APNS_TEAM_ID")
64
+
///
65
+
/// let productionConfig = APNSClientConfiguration(
/// As shown above, the same key can be used for both the development and production environments.
95
+
///
96
+
/// - Important: Make sure not to store your APNs key within your code or repo directly, and opt to store it via a secure store specific to your deployment, such as in a .env supplied at deploy time.
97
+
///
98
+
/// You can determine which environment is being used in your app by checking its entitlements, and including the information along with the device token when sending it to your server:
99
+
/// ```swift
100
+
/// enum APNSDeviceTokenEnvironment: String {
101
+
/// case production
102
+
/// case development
103
+
/// }
104
+
///
105
+
/// /// Get the APNs environment from the embedded
106
+
/// /// provisioning profile, or nil if it can't
107
+
/// /// be determined.
108
+
/// ///
109
+
/// /// Note that both TestFlight and the App Store
110
+
/// /// don't have provisioning profiles, and always
111
+
/// /// run in the production environment.
112
+
/// var pushEnvironment: APNSDeviceTokenEnvironment? {
113
+
/// #if canImport(AppKit)
114
+
/// let provisioningProfileURL = Bundle.main.bundleURL
/// Note that the simulator doesn't have a provisioning profile, and will always register under the development environment.
156
+
///
157
+
/// - Parameters:
158
+
/// - config: The APNs configuration.
159
+
/// - eventLoopGroupProvider: Specify how the ``NIOCore/EventLoopGroup`` will be created. Example: `.shared(app.eventLoopGroup)`
160
+
/// - responseDecoder: A decoder to use when decoding responses from the APNs server. Example: `JSONDecoder()`
161
+
/// - requestEncoder: An encoder to use when encoding notifications. Example: `JSONEncoder()`
162
+
/// - byteBufferAllocator: The allocator to use.
163
+
/// - id: The container ID to access the configuration under.
164
+
/// - isDefault: A flag to specify the configuration as the default when ``Vapor/Application/APNS/client`` is called. The first configuration that doesn't specify `false` is automatically configured as the default.
Copy file name to clipboardexpand all lines: Sources/VaporAPNS/Application+APNS.swift
+62
Original file line number
Diff line number
Diff line change
@@ -47,3 +47,65 @@ extension Application {
47
47
}
48
48
}
49
49
}
50
+
51
+
extensionApplication.APNS{
52
+
/// Configure both a production and development APNs environment.
53
+
///
54
+
/// This convenience method creates two clients available via ``client(_:)`` with ``APNSContainers/ID/production`` and ``APNSContainers/ID/development`` that make it easy to support both development builds (ie. run from Xcode) and release builds (ie. TestFlight/App Store):
55
+
///
56
+
/// ```swift
57
+
/// /// The .p8 file as a string.
58
+
/// guard let apnsKey = Environment.get("APNS_KEY_P8")
59
+
/// else { throw Abort(.serviceUnavailable) }
60
+
///
61
+
/// app.apns.configure(.jwt(
62
+
/// privateKey: try .loadFrom(string: apnsKey),
63
+
/// /// The identifier of the key in the developer portal.
/// For more control over configuration, including sample code to determine the environment an APFs device token belongs to, see ``APNSContainers/use(_:eventLoopGroupProvider:responseDecoder:requestEncoder:byteBufferAllocator:as:isDefault:)``.
82
+
///
83
+
/// - Note: The same key can be used for both the development and production environments.
84
+
///
85
+
/// - Important: Make sure not to store your APNs key within your code or repo directly, and opt to store it via a secure store specific to your deployment, such as in a .env supplied at deploy time.
86
+
///
87
+
/// - Parameter authenticationMethod: An APNs authentication method to use when connecting to Apple's production and development servers.
0 commit comments