Giter VIP home page Giter VIP logo

swiftyapns's Introduction

SwiftyAPNS

HTTP/2 Apple Push Notification Service for Swift.

There are two ways how the provider server can communicate with the Apple Push Notification service (APNs). The framework is supported both token-based and certificate-based authentication, but the former is preferred.

JWT Token provider

Before sending any pushes need to instantiate the APNs provider. For provider with a token-based connection need to know Apple Developer Team ID (can be getting from the Account page) and Apple Push Notification Authentication Key.

let keyP8 = <#Apple Auth Key (.p8) content#>
let keyId = <#Apple Auth Key ID#>
let teamId = <#Apple Developer Team ID#>
let provider = APNSProvider.init(p8: keyP8, keyId: keyId, teamId: teamId)

Payload examples

Plain payload:

let plain = APNSPayload(alert: .plain(plain: "Plain notification."))

Localized payload:

var alert = APSLocalizedAlert()
alert.title = "Title"
alert.subtitle = "Subtitle"
alert.body = "Localized notification body."
let localized = APNSPayload(alert: .localized(alert: alert))

Notification example

To create Notification we need a DeviceToken, a Topic, and a Payload.

var options = APNSNotificationOptions.default
options.type = .alert
options.topic = <#Remote Notification Topic#
let notification = APNSNotification.init(payload: <#Notification Payload#>,
                                         token: <#Device Token#>,
                                         options: options)

Sending push notifications

The values in responses can be handled asynchronously.

    do {
        let responce = try await provider.push(notification)
        // Push Notification was successfully sent
    } catch {
        // Push Notification failure
    }

License

MIT License

swiftyapns's People

Contributors

polyitan avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.