Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/boostcode/Tori-APNS
Tori APNS adds support to Kitura to send easily Apple Push Notification using HTTP/2
https://github.com/boostcode/Tori-APNS
Last synced: 3 months ago
JSON representation
Tori APNS adds support to Kitura to send easily Apple Push Notification using HTTP/2
- Host: GitHub
- URL: https://github.com/boostcode/Tori-APNS
- Owner: boostcode
- Created: 2016-08-24T07:31:48.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2017-04-27T08:35:35.000Z (over 7 years ago)
- Last Synced: 2024-07-23T01:42:42.644Z (4 months ago)
- Language: Swift
- Size: 303 KB
- Stars: 21
- Watchers: 3
- Forks: 3
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
- TheList - Tori-APNS - iOS APSN push notification sender. (Server Side Utilities / iOS Notifications)
README
![Tori APNS](https://github.com/boostcode/Tori-APNS/blob/master/.github/tori-apns-logo.png?raw=true)
[![Issues](https://img.shields.io/github/issues/boostcode/tori-APNS.svg?style=flat)](https://github.com/boostcode/tori-APNS/issues)
[![codebeat badge](https://codebeat.co/badges/193276f6-ea57-4cb5-9e8d-306df4169b01)](https://codebeat.co/projects/github-com-boostcode-tori-apns)![macOS](https://img.shields.io/badge/os-macOS-green.svg?style=flat)
![Linux](https://img.shields.io/badge/os-linux-green.svg?style=flat)
![Swift 2.2 compatible](https://img.shields.io/badge/swift2-compatible-4BC51D.svg?style=flat)
![Apache 2](https://img.shields.io/badge/license-Apache2-blue.svg?style=flat)`tori-APNS` is a simple lib that allows you to send Apple Push Notifications using `curl HTTP/2` protocol in linux & macOS, it is compatible starting from `swift 3`.
# Usage
A quick guide, step by step, about how to use this lib.
## 1- Install libcurl with http/2 supportIn macOS using `brew` you can easily do with:
```shell
brew reinstall curl --with-openssl --with-nghttp2
brew link curl --force
```## 2- Add tori-APNS to your project
Add this row to your `Package.swift` file:
```swift
.Package(url: "https://github.com/boostcode/tori-APNS.git", majorVersion: 0, minor: 2)
```And then run `swift fetch` command.
## 3- Prepare certificates
Create your APNS certificates, then export as `P12` file without password then proceed in this way in your shell:
```shell
openssl pkcs12 -in path.p12 -out apns-crt.pem -clcerts -nokeys
openssl pkcs12 -in path.p12 -out apns-key.pem -nocerts -nodes
```## 4- Integrate in your app
ToriAPNS is pretty easy to be used, first of all add this line on top of your file:
```swift
import ToriAPNS
```then instantiate a `var` to handle pushes:
```swift
let push = APNS.init(withCerts: APNSCertificate(certPath: "/path/of/your file/apns-crt.pem",
keyPath: "/path/of/your file/apns-key.pem"))
````APNS.init` takes a second parameter `inSandbox` that is `true` by default, if you switch to `false` pushes will be sent using production gateway.
Then create a payload for a push message:
```swift
let payload = APNSPayload(withText: "Test")
```In this new implementation we have 7 parameters that we can manage:
- `badge`: take care of the badge counter
- `text`: is the message that will be shown in the push
- `ttl`: is the time to live of the push that is going to be sent (0 is max value)
- `topic`: allows you to tag a push for a type of content
- `id`: allows you to easily track the push
- `priority`: we can manage to send push with max priority `.high` or `.standard`
- `extra`: you can provide extra fields to the push message using a dictionary of type `[String: String]`Finally you have to send your push using `send` passing the `payload` you created just before and the `pushToken` of the receiver:
```swift
push.send(payload: payload, to: "12345678")
```So the overall structure in your app should look pretty similar to:
```swift
let push = APNS.init(withCerts: APNSCertificate(certPath: "/path/of/your file/apns-crt.pem",
keyPath: "/path/of/your file/apns-key.pem"))let payload = APNSPayload(withText: "Test")
push.send(payload: payload, to: "12345678")
```And then use again `swift build` command.