Giter Site home page Giter Site logo

mono0926 / apns Goto Github PK

View Code? Open in Web Editor NEW
27.0 3.0 2.0 22 KB

APNs(Apple Push Notification Service) SDK

Home Page: https://medium.com/swift-column/apns-fbd547c5919

License: MIT License

Swift 100.00%
apns apns2 apns-http2 apns-http apns-sender swift4 swiftpm macos push-notifications notifications

apns's Introduction

APNS 

APNS initialization

There are two ways to initialize APNS instance.

Example

class APNSTests: XCTestCase {
    var target: APNS!
    private let deviceToken: DeviceToken = "0c34a62170c1c0be603780e6458b20dc902730094805b87bef896e6f5ed9bbcb"

    func testSend_Code() throws {
        // Initialize from the config file
        target = try APNS(configPath: "/Users/mono/Documents/Config.plist")

        // Or from each argument
//        target = try APNS(keyPath: "YOUR_p8_KEY_PATH",
//                          keyId: "YOUR_KEY_ID",
//                          teamId: "YOUR_TEAM_ID",
//                          environment: .sandbox, .production or .all) // environmentは省略可能

        // All fields can be amitted
        let alert = Alert(title: "title",
                          subtitle: "subtitle",
                          body: "body",
                          titleLocalizationKey: nil,
                          titleLocalizationArguments: nil,
                          actionLocalizationKey: nil,
                          bodyLocalizationKey: nil,
                          bodyLocalizationArguments: nil,
                          launchImage: nil)
        let aps = Aps(alert: alert,
                      badge: nil, // Can be omitted below
                      sound: "Default",
                      contentAvailable: nil,
                      category: nil,
                      threadId: nil)
        let payload = Payload(aps: aps,
                              custom: Custom(test: "custom-value")) //  Can be omitted
        let request = APNSRequest(topic: "com.mono0926.notification.example",
                                  payload: payload,
                                  apnsIdentifier: UUID(), // Can be omitted below
                                  priority: .immediately,
                                  expiration: Date().addingTimeInterval(3600),
                                  collapseIdentifier: "collapse-identifier")
        
        let results = try target.send(request: request,
                        deviceTokens: [deviceToken])
        results.forEach { print($0) }
    }

    func testSend_JSON() throws {
        target = try APNS(configPath: "/Users/mono/Documents/Config.plist")

        let payload = Payload(aps: try Aps(jsonPath: "/Users/mono/Documents/aps.json"),
                              custom: try Custom(jsonPath: "/Users/mono/Documents/custom.json"))

        let request = APNSRequest(topic: "com.mono0926.notification.example",
                                  payload: payload)

        let results = try target.send(request: request,
                                      deviceTokens: [deviceToken])
        results.forEach { print($0) }
    }
}

struct Custom: Codable, CustomPayload {
    let test: String
}

apns's People

Contributors

kentakudo avatar mono0926 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

apns's Issues

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.