What's New

Swift 4

2017-08-15T12:14:44Z
  • update dependencies
  • update to Swift 4
  • update readme with more configuration details
  • drop embedded LibreSSL
  • logger improvements

EasyAPNS

Swift APNS client built by wrapping libcurl's easy interface.

Dependecies

  • CURL with HTTP/2 support

On macOS HTTP/2 can be installed with Homebrew using brew install curl --with-openssl --with-nghttp2, then you also have to link brew's curl by adding flags -L/usr/local/opt/curl/lib -I/usr/local/opt/curl/include (in Xcode - project's build settings -> Linking -> Other Librarian/Linker flags)

  • LibreSSL/OpenSSL

Starting from v1.0.0 EasyAPNS no longer includes LibreSSL, thus it must be explicitly linked.

Example setup

Developer account

In order to be able to use APNS you need to properly configure you developer account and capabilities of your applications. You can find out more at Apple website,especially in Provider-to-APNs Connection Trust section - which explains what is necessary in order to be able to establish APNS connection.

Generate Xcode project for debugging

swift package -Xswiftc -I/usr/local/opt/libressl/include/ -Xlinker -L/usr/local/opt/libressl/lib -Xlinker -L/usr/local/opt/curl/lib -Xswiftc -I/usr/local/opt/curl/include -Xswiftc "-DDEBUG" generate-xcodeproj

Note: this command assumes you have installed LibreSSL and CURL with Homebrew, if you're using OpenSSL instead or another package manager make sure to properly adjust the linking flags.

Example usage

import EasyAPNS
import libc
import Foundation

class FeedbackCollector: EasyApnsDelegate {
    
    func sendingFeedback(_ messageEnvelope: MessageEnvelope) {
        if case .successfullySent(let apnsId) = messageEnvelope.status {
            print(apnsId ?? "no apns id")
        } else {
            print(messageEnvelope.status)
        }
    }
}


do {
    let devToken = "...";
    let appBundle = "...";
    
    var message = try Message(deviceToken: devToken, appBundle: appBundle)
    message.alert = .message("Greetings from EasyAPNS notification :)")
    message.badge = 2
    
    // JWT 
    let easyApns = try EasyApns(environment: .development, developerTeamId: "...", keyId: "...", keyPath: "...")
    
    //    let easyApns = EasyApns(environment: .development, certificatePath: "...", rawCertificatePassphrase: "...", caAuthorityPath: "...")
    
    let collector = FeedbackCollector()
    easyApns.delegate = collector
    
    try easyApns.enqueue(message)
    try easyApns.enqueue(message)
    let unsuccessful = easyApns.sendEnqueuedMessages()
    
    print("\nUnsuccessful")
    dump(unsuccessful)
    
    
} catch {
    print(error)
}

Description

  • Swift Tools 4.0.0
View More Packages from this Author

Dependencies

Last updated: Tue Apr 23 2024 01:03:10 GMT-0900 (Hawaii-Aleutian Daylight Time)