An open API service indexing awesome lists of open source software.

https://github.com/hagmas/apnskit

A framework to send Apple Notifications
https://github.com/hagmas/apnskit

apns notification-service playground swift

Last synced: 7 months ago
JSON representation

A framework to send Apple Notifications

Awesome Lists containing this project

README

          

# APNsKit
A framework to send Apple notifications.

[![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage)

## 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
```swift
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](https://developer.apple.com/library/content/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/CommunicatingwithAPNs.html#//apple_ref/doc/uid/TP40008194-CH11-SW11)

#2 [Apple's Payload Key Reference](https://developer.apple.com/library/content/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/PayloadKeyReference.html#//apple_ref/doc/uid/TP40008194-CH17-SW1)

## Requirements
* Xcode 8.2.1
* Swift 3.0

## Installation
* APNsKit doesn't include any external depenancies.
* APNsKit currently supports only Carthage.
### [Carthage](https://github.com/Carthage/Carthage)

**Tested with `carthage version`: `0.20.1`**

Add this to `Cartfile`

```
github "hagmas/APNsKit"
```

```bash
$ carthage update
```