/vapor-fcm

Firebase Notifications framework for Vapor, written in Swift

Primary LanguageSwiftMIT LicenseMIT

Vapor FCM

Build Status codebeat badge Platforms Package Managers License: MIT Twitter Follow

Simple Vapor framework for sending Firebase Cloud Messages.

Why?

Do you want to write your awesome server in Swift using Vapor? At some point, you'll probably need to send Push Notifications to Android as well 😉

Features

  • Full message Payload support: badges and sounds for iOS
  • Response parsing, instant send response feedback
  • Custom data payload support
  • Send message to Devices and Topics

Vapor Versions

  • Use Vapor-FCM version 1.x for Vapor 1.x
  • Use Vapor-FCM version 2.x for Vapor 2.x

💻 Installation

Swift Package Manager

.Package(url: "https://github.com/mdab121/vapor-fcm.git", majorVersion: 2, minor: 1)

🔢 Usage

Simple Example

Sending a simple FCM Message is really simple. Just create a Firebase object that will deliver your messages.

let firebase = try Firebase(drop: droplet, keyPath: "/path/to/your/key")

Create a Message

let payload = Payload(text: "Hello VaporFCM!")
let message = Message(payload: payload)

And now, simply send your message to a single device!

let token: DeviceToken = "this_is_a_device_token"
let response = try firebase.send(message: message, to: token)
if response.success {
	// Handle success
} else {
	// Handle error
}

You can also send messages to Topics

let topic: Topic = "cats"
let response = try firebase.send(message: message, to: topic)
if response.success {
	// Handle success
} else {
	// Handle error
}