Skip to content

Tori APNS adds support to Kitura to send easily Apple Push Notification using HTTP/2

Notifications You must be signed in to change notification settings

boostcode/Tori-APNS

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Tori APNS

Issues codebeat badge

macOS Linux Swift 2.2 compatible Apache 2

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 support

In macOS using brew you can easily do with:

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:

.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:

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:

import ToriAPNS

then instantiate a var to handle pushes:

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:

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:

push.send(payload: payload, to: "12345678")

So the overall structure in your app should look pretty similar to:

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.

About

Tori APNS adds support to Kitura to send easily Apple Push Notification using HTTP/2

Resources

Stars

Watchers

Forks

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •  

Languages