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
try apnsConn.send(BasicNotification(aps: aps), pushType: .alert, to: "98AAD4A2398DDC58595F02FA307DF9A15C18B6111D1B806949549085A8E6A55D").wait()
31
43
try apns.close().wait()
@@ -38,22 +50,16 @@ exit(0)
38
50
[`APNSwiftConfiguration`](https://github.com/kylebrowning/swift-nio-http2-apns/blob/master/Sources/APNSwift/APNSwiftConfiguration.swift) is a structure that provides the system with common configuration.
@@ -65,22 +71,6 @@ let apnsConfig = try APNSwiftConfiguration(keyIdentifier: "9UC9ZLQ8YW",
65
71
environment: .sandbox)
66
72
```
67
73
68
-
### Signer
69
-
70
-
[`APNSwiftSigner`](https://github.com/kylebrowning/swift-nio-http2-apns/blob/master/Sources/APNSwift/APNSwiftSigner.swift) provides a structure to sign the payloads with. This should be loaded into memory at the configuration level. It requires the data to be in a ByteBuffer format.
71
-
72
-
```swift
73
-
let url =URL(fileURLWithPath: "/Users/kylebrowning/Downloads/AuthKey_9UC9ZLQ8YW.p8")
var byteBuffer =ByteBufferAllocator().buffer(capacity: data.count)
81
-
byteBuffer.writeBytes(data)
82
-
let signer =try! APNSwiftSigner.init(buffer: byteBuffer)
83
-
```
84
74
### APNSwiftConnection
85
75
86
76
[`APNSwiftConnection`](https://github.com/kylebrowning/swift-nio-http2-apns/blob/master/Sources/APNSwift/APNSwiftConnection.swift) is a class with methods thats provides a wrapper to NIO's ClientBootstrap. The `swift-nio-http2` dependency is utilized here. It also provides a function to send a notification to a specific device token string.
@@ -113,60 +103,6 @@ let alert = ...
113
103
let aps =APNSwiftPayload(alert: alert, badge: 1, sound: .normal("cow.wav"))
114
104
```
115
105
116
-
## Putting it all together
117
-
118
-
```swift
119
-
let group =MultiThreadedEventLoopGroup(numberOfThreads: 1)
120
-
var verbose =true
121
-
122
-
let signer =try!APNSwiftSigner(filePath: "/Users/kylebrowning/Desktop/AuthKey_9UC9ZLQ8YW.p8")
123
-
124
-
let apnsConfig =APNSwiftConfiguration(keyIdentifier: "9UC9ZLQ8YW",
125
-
teamIdentifier: "ABBM6U9RM5",
126
-
signer: signer,
127
-
topic: "com.grasscove.Fern",
128
-
environment: .sandbox)
129
-
130
-
let apns =try APNSwiftConnection.connect(configuration: apnsConfig, on: group.next()).wait()
131
-
132
-
if verbose {
133
-
print("* Connected to \(apnsConfig.url.host!) (\(apns.channel.remoteAddress!)")
134
-
}
135
-
136
-
struct AcmeNotification:APNSwiftNotification {
137
-
let acme2: [String]
138
-
let aps: APNSwiftPayload
139
-
140
-
init(acme2: [String], aps: APNSwiftPayload) {
141
-
self.acme2= acme2
142
-
self.aps= aps
143
-
}
144
-
}
145
-
146
-
let alert = APNSwiftPayload.APNSwiftAlert(title: "Hey There", subtitle: "Subtitle", body: "Body")
147
-
let apsSound = APNSwiftPayload.APNSSoundDictionary(isCritical: true, name: "cow.wav", volume: 0.8)
148
-
let aps =APNSwiftPayload(alert: alert, badge: 0, sound: .critical(apsSound), hasContentAvailable: true)
149
-
let temp =try!JSONEncoder().encode(aps)
150
-
let string =String(bytes: temp, encoding: .utf8)
151
-
let notification =AcmeNotification(acme2: ["bang", "whiz"], aps: aps)
152
-
153
-
do {
154
-
let expiry =Date().addingTimeInterval(5)
155
-
for_in1...5 {
156
-
try apns.send(notification, pushType: .alert, to: "98AAD4A2398DDC58595F02FA307DF9A15C18B6111D1B806949549085A8E6A55D", expiration: expiry, priority: 10).wait()
157
-
try apns.send(notification, pushType: .alert, to: "98AAD4A2398DDC58595F02FA307DF9A15C18B6111D1B806949549085A8E6A55D", expiration: expiry, priority: 10).wait()
158
-
try apns.send(notification, pushType: .alert, to: "98AAD4A2398DDC58595F02FA307DF9A15C18B6111D1B806949549085A8E6A55D", expiration: expiry, priority: 10).wait()
159
-
try apns.send(notification, pushType: .alert, to: "98AAD4A2398DDC58595F02FA307DF9A15C18B6111D1B806949549085A8E6A55D", expiration: expiry, priority: 10).wait()
160
-
}
161
-
} catch {
162
-
print(error)
163
-
}
164
-
165
-
try apns.close().wait()
166
-
try group.syncShutdownGracefully()
167
-
exit(0)
168
-
```
169
-
170
106
### Custom Notification Data
171
107
172
108
Apple provides engineers with the ability to add custom payload data to each notification. In order to facilitate this we have the `APNSwiftNotification`.
@@ -192,9 +128,12 @@ let res = try apns.send(notification, to: "de1d666223de85db0186f654852cc96055112
0 commit comments