wildthink / APNSwift

HTTP/2 Swift APNS library for notification provider

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

APNSwift

HTTP/2 Apple Push Notification Service (APNs) push provider written in Swift

Cocoapods Compatible Platform License

Features

  • Sends notification using new HTTP/2 protocol
  • Send notifications iOS, tvOS and macOS apps

Installation

##CocoaPods CocoaPods adds supports for Swift and embedded frameworks.

To integrate APNSwift into your Xcode project using CocoaPods, specify it in your Podfile:

pod 'APNSwift'

Usage

Initialization

SecIdentity

let apnsConnection = APNS(identity: certificateIdentity, options: apnsOptions)

PFCS Container (.p12)

guard let apns = APNS(certificatePath: "/path/to/PKCS/certificate", passphrase: "********") else {
    //Failed to create APNS object
    return nil
}

Push Notification options

var apnsOptions = APNS.Options()
apnsOptions.topic = "Weekend deal"
apnsOptions.port = .p2197
apnsOptions.expiry = NSDate()
apnsOptions.development = false

Push

try! apnsConnection.sendPush(tokenList: tokens, payload: jsonPayLoad) {
    (apnsResponse) in
    Swift.print("\n\(apnsResponse.deviceToken)")
    Swift.print("  Status: \(apnsResponse.serviceStatus)")
    Swift.print("  APNS ID: \(apnsResponse.apnsId ?? "")")
    if let errorReason = apnsResponse.errorReason {
        Swift.print("  ERROR: \(errorReason)")
    }
}

About

HTTP/2 Swift APNS library for notification provider

License:MIT License


Languages

Language:Swift 96.2%Language:Ruby 3.8%