@@ -53,6 +53,8 @@ let deviceId = "hex string device id"
53
53
let ary = [IOSNotificationItem.AlertBody("This is the message"), IOSNotificationItem.Sound("default")]
54
54
let n = NotificationPusher()
55
55
56
+ n.apnsTopic = "com.company.my-app"
57
+
56
58
n.pushIOS(configurationName, deviceToken: deviceId, expiration: 0, priority: 10, notificationItems: ary) {
57
59
response in
58
60
@@ -148,7 +150,7 @@ public class NotificationPusher {
148
150
/// Toggle development or production on a global basis.
149
151
public static var development = false
150
152
151
- /// apns-topic
153
+ /// Sets the apns-topic which will be used for iOS notifications.
152
154
public var apnsTopic : String ?
153
155
154
156
var responses = [ NotificationResponse] ( )
@@ -247,6 +249,8 @@ public class NotificationPusher {
247
249
248
250
}
249
251
252
+ /// Initialize given iOS apns-topic string.
253
+ /// This can be set after initialization on the X.apnsTopic property.
250
254
public init( apnsTopic: String) {
251
255
self . apnsTopic = apnsTopic
252
256
}
@@ -282,7 +286,8 @@ public class NotificationPusher {
282
286
}
283
287
}
284
288
}
285
- /// Push multiple messages to one device.
289
+
290
+ /// Push one message to multiple devices.
286
291
/// Provide the previously set configuration name, and zero or more device tokens. The same message will be sent to each device.
287
292
/// Provide the expiration and priority as described here:
288
293
/// https://developer.apple.com/library/mac/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/Chapters/APNsProviderAPI.html
@@ -357,58 +362,6 @@ public class NotificationPusher {
357
362
self . pushIOS ( client, deviceTokens: g, expiration: expiration, priority: priority, notificationJson: jsond, callback: callback)
358
363
}
359
364
360
- /// Push multiple messages to one device.
361
- /// Provide the previously set configuration name, and zero or more device tokens. The same message will be sent to each device.
362
- /// Provide the expiration and priority as described here:
363
- /// https://developer.apple.com/library/mac/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/Chapters/APNsProviderAPI.html
364
- /// Provide a list of IOSNotificationItems.
365
- /// Provide a callback with which to receive any errors which may have occurred.
366
- /// nil is passed to the callback if the push was successful.
367
- /* public func pushIOS(configurationName: String, deviceTokens: [String], expiration: UInt32, priority: UInt8, notificationItems: [IOSNotificationItem], callback: (errorMessage: String?) -> ()) {
368
-
369
- do {
370
- let jsond = try self.itemsToPayloadString(notificationItems)
371
-
372
- NotificationPusher.getStreamIOS(configurationName) {
373
- n in
374
-
375
- if let net = n {
376
-
377
- let request = net.createRequest()
378
- request.setRequestMethod("POST")
379
- request.postBodyBytes = UTF8Encoding.decode(jsond)
380
- request.headers["content-type"] = "application/json; charset=utf-8"
381
- request.headers["apns-expiration"] = "\(expiration)"
382
- request.headers["apns-priority"] = "\(priority)"
383
- request.headers["apns-topic"] = "ca.treefrog.Smirkee"
384
- request.setRequestURI("/3/device/\(deviceToken)")
385
- net.sendRequest(request) {
386
- response, msg in
387
-
388
- NotificationPusher.releaseStreamIOS(configurationName, net: net)
389
-
390
- if let r = response {
391
- let code = r.getStatus().0
392
- if code != 200 {
393
- callback(errorMessage: "Response code \(code)")
394
- } else {
395
- callback(errorMessage: nil)
396
- }
397
- } else {
398
- callback(errorMessage: msg)
399
- }
400
- }
401
-
402
- } else {
403
- callback(errorMessage: "No stream")
404
- }
405
- }
406
-
407
- } catch let e {
408
- callback(errorMessage: "\(e)")
409
- }
410
- }
411
- */
412
365
func itemsToPayloadString( notificationItems: [ IOSNotificationItem] ) - > String {
413
366
var dict = [ String: Any] ( )
414
367
var aps = [ String: Any] ( )
0 commit comments