All Projects → kylebrowning → Apnswift

kylebrowning / Apnswift

Licence: apache-2.0
An HTTP/2 APNS library built on swift-nio

Programming Languages

swift
15916 projects

Labels

Projects that are alternatives of or similar to Apnswift

Gunfish
No description or website provided.
Stars: ✭ 35 (-90.74%)
Mutual labels:  apns
mod push appserver
Simple and extendable appserver for XMPP pushes (aka. XEP-0357)
Stars: ✭ 24 (-93.65%)
Mutual labels:  apns
Houston
Apple Push Notifications; No Dirigible Required
Stars: ✭ 2,973 (+686.51%)
Mutual labels:  apns
apns2
Node client for connecting to Apple's Push Notification Service using the new HTTP/2 protocol with JSON web tokens
Stars: ✭ 66 (-82.54%)
Mutual labels:  apns
PUSHTestFCM
[FireMonkey] Push test project
Stars: ✭ 17 (-95.5%)
Mutual labels:  apns
azure-notificationhubs-java-backend
Azure Notification Hubs SDK for Java
Stars: ✭ 31 (-91.8%)
Mutual labels:  apns
mobile-messaging-sdk-ios
Mobile Messaging SDK for iOS
Stars: ✭ 45 (-88.1%)
Mutual labels:  apns
Apnotic
A Ruby APNs HTTP/2 gem able to provide instant feedback.
Stars: ✭ 360 (-4.76%)
Mutual labels:  apns
PushMeBaby
iOS Push Notification Debug App. You can use this app during iOS Push Notification (development or production) to push notifications on your device from your Mac.
Stars: ✭ 47 (-87.57%)
Mutual labels:  apns
Pushok
PHP client for Apple Push Notification Service (APNs) - Send push notifications to iOS using the new APNs HTTP/2 protocol with token-based (JWT with p8 private key)
Stars: ✭ 260 (-31.22%)
Mutual labels:  apns
dotAPNS
dotAPNS is a library used to send push notifications to Apple devices using Apple Push Notification service via HTTP/2 API.
Stars: ✭ 80 (-78.84%)
Mutual labels:  apns
aioapns
An efficient APNs Client Library for Python/asyncio
Stars: ✭ 60 (-84.13%)
Mutual labels:  apns
node-apn-http2
Communicate with Apple Push Notification Service via native Node.js v8.8.1+ HTTP2 module (node-apn drop-in)
Stars: ✭ 25 (-93.39%)
Mutual labels:  apns
APNsKit
A framework to send Apple Notifications
Stars: ✭ 20 (-94.71%)
Mutual labels:  apns
Vapor Apns
Simple APNS Library for Vapor (Swift)
Stars: ✭ 344 (-8.99%)
Mutual labels:  apns
pushex
Push notifications for Elixir
Stars: ✭ 96 (-74.6%)
Mutual labels:  apns
ejabberd mod apns
An ejabberd module to send PUSH messages to iOS devices through APNS
Stars: ✭ 31 (-91.8%)
Mutual labels:  apns
Onesignal Ios Sdk
OneSignal is a free push notification service for mobile apps. This plugin makes it easy to integrate your native iOS app with OneSignal. https://onesignal.com
Stars: ✭ 370 (-2.12%)
Mutual labels:  apns
Apns4erl
Apple Push Notification Server for Erlang
Stars: ✭ 352 (-6.88%)
Mutual labels:  apns
MongoosePush
MongoosePush is a simple Elixir RESTful service allowing to send push notification via FCM and/or APNS.
Stars: ✭ 101 (-73.28%)
Mutual labels:  apns

sswg:incubating|94x20 License Build Swift

APNSwift

A non-blocking Swift module for sending remote Apple Push Notification requests to APNS built on http/2, SwiftNIO for use on server side swift platforms.

Installation

To install APNSwift, just add the package as a dependency in your Package.swift.

dependencies: [
    .package(url: "https://github.com/kylebrowning/APNSwift.git", .upToNextMinor(from: "1.3.0"))
]

Getting Started

struct BasicNotification: APNSwiftNotification {
    let aps: APNSwiftPayload
}
let group = MultiThreadedEventLoopGroup(numberOfThreads: 1)
var logger = Logger(label: "com.apnswift")
logger.logLevel = .debug
let apnsConfig = try APNSwiftConfiguration(
    authenticationMethod: .jwt(
        key: .private(filePath: "/Users/kylebrowning/Desktop/AuthKey_9UC9ZLQ8YW.p8"),
        keyIdentifier: "9UC9ZLQ8YW",
        teamIdentifier: "ABBM6U9RM5"
    ),
    topic: "com.grasscove.Fern",
    environment: .sandbox,
    logger: logger
)

let apns = try APNSwiftConnection.connect(configuration: apnsConfig, on: group.next()).wait()
let aps = APNSwiftPayload(alert: .init(title: "Hey There", subtitle: "Subtitle", body: "Body"), hasContentAvailable: true)
try apns.send(BasicNotification(aps: aps), pushType: .alert, to: "98AAD4A2398DDC58595F02FA307DF9A15C18B6111D1B806949549085A8E6A55D").wait()
try apns.close().wait()
try group.syncShutdownGracefully()
exit(0)

APNSwiftConfiguration

APNSwiftConfiguration is a structure that provides the system with common configuration.

let apnsConfig = try APNSwiftConfiguration(
    authenticationMethod: .jwt(
        key: .private(filePath: "/Users/kylebrowning/Desktop/AuthKey_9UC9ZLQ8YW.p8"),
        keyIdentifier: "9UC9ZLQ8YW",
        teamIdentifier: "ABBM6U9RM5"
    ),
    topic: "com.grasscove.Fern",
    environment: .sandbox,
    logger: logger
)

Example APNSwiftConfiguration

let signer = ...
let apnsConfig = try APNSwiftConfiguration(keyIdentifier: "9UC9ZLQ8YW",
                                   teamIdentifier: "ABBM6U9RM5",
                                   signer: signer),
                                   topic: "com.grasscove.Fern",
                                   environment: .sandbox)

APNSwiftConnection

APNSwiftConnection is a class with methods thats provides a wrapper to NIO's ClientBootstrap. The swift-nio-http2 dependency is utilized here. It also provides a function to send a notification to a specific device token string.

Example APNSwiftConnection

let apnsConfig = ...
let apns = try APNSwiftConnection.connect(configuration: apnsConfig, on: group.next()).wait()

APNSwiftAlert

APNSwiftAlert is the actual meta data of the push notification alert someone wishes to send. More details on the specifics of each property are provided here. They follow a 1-1 naming scheme listed in Apple's documentation

Example APNSwiftAlert

let alert = APNSwiftAlert(title: "Hey There", subtitle: "Full moon sighting", body: "There was a full moon last night did you see it")

APNSwiftPayload

APNSwiftPayload is the meta data of the push notification. Things like the alert, badge count. More details on the specifics of each property are provided here. They follow a 1-1 naming scheme listed in Apple's documentation

Example APNSwiftPayload

let alert = ...
let aps = APNSwiftPayload(alert: alert, badge: 1, sound: .normal("cow.wav"))

Custom Notification Data

Apple provides engineers with the ability to add custom payload data to each notification. In order to facilitate this we have the APNSwiftNotification.

Example

struct AcmeNotification: APNSwiftNotification {
    let acme2: [String]
    let aps: APNSwiftPayload

    init(acme2: [String], aps: APNSwiftPayload) {
        self.acme2 = acme2
        self.aps = aps
    }
}

let apns: APNSwiftConnection: = ...
let aps: APNSwiftPayload = ...
let notification = AcmeNotification(acme2: ["bang", "whiz"], aps: aps)
let res = try apns.send(notification, to: "de1d666223de85db0186f654852cc960551125ee841ca044fdf5ef6a4756a77e").wait()

Using PEM instead of P8

Note: this is blocking

var apnsConfig = try APNSwiftConfiguration(
    authenticationMethod: .tls(
        privateKeyPath: "/Users/kylebrowning/Projects/swift/Fern/development_com.grasscove.Fern.pkey",
        pemPath: "/Users/kylebrowning/Projects/swift/Fern/development_com.grasscove.Fern.pem"
    ),
    topic: "com.grasscove.Fern",
    environment: .sandbox
)
let apns = try APNSwiftConnection.connect(configuration: apnsConfig, on: group.next()).wait()

Need a completely custom arbtirary payload and dont like being typecast?

APNSwift provides the ability to send raw payloads. You can use Data, ByteBuffer, DispatchData, Array Though this is to be used with caution. APNSwift cannot gurantee delivery if you do not have the correct payload. For more information see: Creating APN Payload

let notificationJsonPayload = ...
let data: Data = try! encoder.encode(notificationJsonPayload)
try apns.send(raw: data, pushType: .alert, to: "<DEVICETOKEN>")

Original pitch and discussion on API

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].