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
Add semantic safe API for alert notifications (#144)
# Motivation
We want to provide new APIs that are semantically safe when sending alerts to APNs. These APIs should feel native in Swift and not leak too many APIs of the APNs interface.
# Modification
This PR creates a few new semantic types to represent currency types from the APNs API. Furthermore, the PR adds new types for the alert notification and a convenience method to send alert notifications with the APNSClient.
# Result
We can now send alert notifications.
Copy file name to clipboardExpand all lines: Sources/APNSwift/APNSClient.swift
+72
Original file line number
Diff line number
Diff line change
@@ -140,6 +140,78 @@ public final class APNSClient<Decoder: APNSJSONDecoder, Encoder: APNSJSONEncoder
140
140
// MARK: - Raw sending
141
141
142
142
extensionAPNSClient{
143
+
/// Sends a notification to APNs.
144
+
///
145
+
/// - Important: This method exposes the raw API for APNs. In general, this should be avoided
146
+
/// and the semantic-safe APIs should be used instead.
147
+
///
148
+
/// - Parameters:
149
+
/// - payload: The notification payload.
150
+
///
151
+
/// - deviceToken: The hexadecimal bytes that identify the user’s device. Your app receives the bytes for this device token
152
+
/// when registering for remote notifications.
153
+
///
154
+
/// - pushType: The value of this header must accurately reflect the contents of your notification’s payload. If there’s a mismatch,
155
+
/// or if the header is missing on required systems, APNs may return an error, delay the delivery of the notification, or drop it altogether.
156
+
///
157
+
/// - apnsID: A canonical UUID that identifies the notification. If there is an error sending the notification,
158
+
/// APNs uses this value to identify the notification to your server. The canonical form is 32 lowercase hexadecimal digits,
159
+
/// displayed in five groups separated by hyphens in the form 8-4-4-4-12. An example UUID is as follows: 123e4567-e89b-12d3-a456-42665544000.
160
+
/// If you omit this, a new UUID is created by APNs and returned in the response.
161
+
///
162
+
/// - expiration: The date when the notification is no longer valid and can be discarded. If this value is not `none`,
163
+
/// APNs stores the notification and tries to deliver it at least once, repeating the attempt as needed if it is unable to deliver the notification the first time.
164
+
/// If the value is `immediately`, APNs treats the notification as if it expires immediately and does not store the notification or attempt to redeliver it.
165
+
///
166
+
/// - priority: The priority of the notification. If you omit this header, APNs sets the notification priority to `immediately`.
167
+
///
168
+
/// - topic: The topic for the notification. In general, the topic is your app’s bundle ID/app ID.
169
+
/// It can have a suffix based on the type of push notification. If you’re using a certificate that supports PushKit VoIP or watchOS complication notifications,
170
+
/// you must include this header with bundle ID of you app and if applicable, the proper suffix.
171
+
/// If you’re using token-based authentication with APNs, you must include this header with the correct bundle ID and suffix combination.
172
+
///
173
+
/// - collapseID: An identifier you use to coalesce multiple notifications into a single notification for the user.
174
+
/// Typically, each notification request causes a new notification to be displayed on the user’s device.
175
+
/// When sending the same notification more than once, use the same value in this header to coalesce the requests.
176
+
/// The value of this key must not exceed 64 bytes.
177
+
///
178
+
/// - deadline: Point in time by which sending the notification to APNs must complete.
179
+
///
180
+
/// - logger: The logger to use for sending this notification.
0 commit comments