Swiftpack.co -  pusher/push-notifications-server-swift as Swift Package
Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
pusher/push-notifications-server-swift
Pusher Beams Swift Server SDK
.package(url: "https://github.com/pusher/push-notifications-server-swift.git", from: "1.0.3")

Pusher Beams Swift Server SDK

Build Status

Building the project

swift build

Running the tests

swift test

Installation

To include PushNotifications in your package, add the following to your Package.swift file.

// swift-tools-version:4.0
import PackageDescription

let package = Package(
    name: "YourProjectName",
    dependencies: [
        ...
        .package(url: "git@github.com:pusher/push-notifications-server-swift.git", from: "1.0.3",
    ],
    targets: [
      .target(name: "YourProjectName", dependencies: ["PushNotifications", ... ])
    ]
)

Use import PushNotifications to access the APIs.

Example

// Pusher Beams Instance Id.
let instanceId = "c7c52433-8c65-43e6-9ef2-922d9ed9e196"
// Pusher Beams Secret Key.
let secretKey = "39817C9BCBF7F053CB151343D54EE75"

// PushNotifications instance.
let pushNotifications = PushNotifications(instanceId: instanceId, secretKey: secretKey)

// Interests array.
let interests = ["pizza", "donuts"]
// Publish request: APNs, FCM.
let publishRequest = [
  "apns": [
    "aps": [
      "alert": "Hello"
    ]
  ],
  "fcm": [
    "notification": [
      "title": "Hello",
      "body":  "Hello, world",
    ]
  ]
]

// Publish To Interests
pushNotifications.publishToInterests(interests, publishRequest, completion: { result in
    switch result {
    case .value(let publishId):
        print("\(publishId)")
    case .error(let error):
        print("\(error)")
    }
})

// Publish To Users
pushNotifications.publishToUsers(["jonathan", "jordan", "luís", "luka", "mina"], publishRequest, completion: { result in
    switch result {
    case .value(let publishId):
        print("\(publishId)")
    case .error(let error):
        print("\(error)")
    }
})

// Authenticate User
pushNotifications.generateToken("Elmo", completion: { result in
    switch result {
    case .value(let jwtToken):
        // 'jwtToken' is a Dictionary<String, String>
        // Example: ["token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJhYWEiLCJleHAiOjE"]
        print("\(jwtToken)")
    case .error(let error):
        print("\(error)")
    }
})

// Delete User
pushNotifications.deleteUser("Elmo", completion: { result in
    switch result {
    case .value:
        print("User deleted 👌")
    case .error(let error):
        print("\(error)")
    }
})

Communication

  • Found a bug? Please open an issue.
  • Have a feature request. Please open an issue.
  • If you want to contribute, please submit a pull request (preferably with some tests).

Credits

Beams is owned and maintained by Pusher.

License

This project is released under the MIT license. See LICENSE for details.

GitHub

link
Stars: 6
Last commit: 2 weeks ago

Ad: Job Offers

iOS Software Engineer @ Perry Street Software
Perry Street Software is Jack’d and SCRUFF. We are two of the world’s largest gay, bi, trans and queer social dating apps on iOS and Android. Our brands reach more than 20 million members worldwide so members can connect, meet and express themselves on a platform that prioritizes privacy and security. We invest heavily into SwiftUI and using Swift Packages to modularize the codebase.

Dependencies

Release Notes

1.0.3
13 weeks ago

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API