APNsKit icon indicating copy to clipboard operation
APNsKit copied to clipboard

A framework to send Apple Notifications

APNsKit

A framework to send Apple notifications.

Carthage compatible

About APNsKit

APNsKit is a swift framework to send Apple notifications to iOS devices. Especially, with Playground it lets you to create interactive tool to send push notifications for debugging purposes. Check out the Playground PushViewController.playground bundled with the Workspace.

Usage

import APNsKit

// Setting header fields is optional. Refer (#1) for configurable header fields of APNs request.
let header = APNsRequest.Header(priority: .p10, topic: "<#The topic of the remote notification#>")

// Create a APNs payload. See Apple's Payload Key Reference (#2) for its specifications.
let payload = APNsPayload(title: "Hello World!", body: "This is APNsKit.", contentAvailable: 1)
let request = APNsRequest(port: .p2197,
                          server: .development,
                          deviceToken: "<#The target device token#>",
                          header: header,
                          payload: payload)

// Create a connection that wraps up URLSession and its authentication challenges.
if let connection = try? Connection(p12FileName: "<#Your p12 file name#>", passPhrase: "<#The pass phrase for the file#>") {
    
    // Send the request to the APNs server. The connection has to be retained until the server responses.
    connection.send(request: request, resultHandler: { result in
        switch result {
        case .success:
            print("Succeeded!")
        case .failure(let code, let message):
            print("Failed to send: \(code), \(message)")
        }
    })
}

#1 HTTP/2 Request to APNs

#2 Apple's Payload Key Reference

Requirements

  • Xcode 8.2.1
  • Swift 3.0

Installation

  • APNsKit doesn't include any external depenancies.
  • APNsKit currently supports only Carthage.

Carthage

Tested with carthage version: 0.20.1

Add this to Cartfile

github "hagmas/APNsKit"
$ carthage update