Skip to content

Releases: MihaelIsaev/FCM

⚡️Swift 6 and async/await

Pre-release

Choose a tag to compare

@MihaelIsaev MihaelIsaev released this 11 Nov 16:59

Many thanks to @gennaro-safehill and @ptoffy for their great contributions!

FCM now supports Swift 6 and async/await!

All the details are in the updated readme

This is a pre-release version, so use it carefully in production.

@ptoffy will test it in staging/production environments before we tag it as a stable release.

Please share your feedback!

Add method to retrieve subscribed topics

Choose a tag to compare

@MihaelIsaev MihaelIsaev released this 14 Mar 22:44
3414d98

Thanks to @chinh-tran

Add image for the push notifications

Choose a tag to compare

@MihaelIsaev MihaelIsaev released this 14 Mar 14:21
cbc8255

FCMApnsConfig initializer now have optional FCMOptions argument which could be used to attach image to the push notification.

Thanks to @paunik

Fix memory issues (#26) by @grahamburgsma

Choose a tag to compare

@MihaelIsaev MihaelIsaev released this 12 Aug 09:57
919d41a
  • Use Vapor client instead to get helpers and reduce lower level work
  • Update all other uses of client
  • Generalize response error handling

Implement one more convenient initialization

Choose a tag to compare

@MihaelIsaev MihaelIsaev released this 23 May 19:02
app.fcm.configuration = .envServiceAccountKeyFields

it will initialize FCM by reading the following environment variables

FCM_EMAIL - `client_email` in service.json
FCM_PROJECT_ID - `project_id` in service.json
FCM_PRIVATE_KEY - `private_key` in service.json

☄️ Implement batch sending

Choose a tag to compare

@MihaelIsaev MihaelIsaev released this 16 May 00:31
// get it from iOS/Android SDK
let token1 = "<YOUR FIREBASE DEVICE TOKEN>"
let token2 = "<YOUR FIREBASE DEVICE TOKEN>"
let token3 = "<YOUR FIREBASE DEVICE TOKEN>"
...
let token100500 = "<YOUR FIREBASE DEVICE TOKEN>"

let notification = FCMNotification(title: "Life is great! 😃", body: "Swift one love! ❤️")
let message = FCMMessage(notification: notification)
application.fcm.batchSend(message, tokens: [token1, token2, token3, ..., token100500]).map {
    print("sent!")
}

🔥 Implement pure APNS to Firebase token converter

Choose a tag to compare

@MihaelIsaev MihaelIsaev released this 15 May 14:40

Now you can throw away Firebase libs from dependencies of your iOS apps because you can send pure APNS tokens to your server and it will register it in Firebase by itself.

It is must have for developers who don't want to add Firebase libs into their apps, and especially for iOS projects who use Swift Package Manager cause Firebase doesn't have SPM support for its libs yet.

How to use

Preparation

  1. Go to Firebase Console -> Project Settings -> Cloud Messaging tab
  2. Copy Server Key from Project Credentials area

Next steps are optional

  1. Put server key into environment variables as FCM_SERVER_KEY=<YOUR_SERVER_KEY>
  2. Put your app bundle identifier into environment variables as FCM_APP_BUNDLE_ID=<APP_BUNDLE_ID>

Tokens registration

/// The simplest way
/// .env here means that FCM_SERVER_KEY and FCM_APP_BUNDLE_ID will be used
application.fcm.registerAPNS(.env, tokens: "token1", "token3", ..., "token100").flatMap { tokens in
    /// `tokens` is array of `APNSToFirebaseToken` structs
    /// which contains:
    /// registration_token - Firebase token
    /// apns_token - APNS token
    /// isRegistered - boolean value which indicates if registration was successful
}

/// instead of .env you could declare your own identifier
extension RegisterAPNSID {
   static var myApp: RegisterAPNSID { .init(appBundleId: "com.myapp") }
}

/// Advanced way
application.fcm.registerAPNS(
    appBundleId: String, // iOS app bundle identifier
    serverKey: String?, // optional server key, if nil then env variable will be used
    sandbox: Bool, // optional sandbox key, false by default
    tokens: [String], // an array of APNS tokens
    on: EventLoop? // optional event loop, if nil then application.eventLoopGroup.next() will be used
).flatMap { tokens in
    /// the same as in above example
}

Fix annoying moments

Choose a tag to compare

@MihaelIsaev MihaelIsaev released this 23 Feb 11:11
  • fix annoying warning: cannot modify client configuration after client has been used
  • add send method with eventLoop argument to avoid manual hop(to:) call
    so now if you send from Request you could write
req.fcm.send(message, on: req.eventLoop)

instead of

req.fcm.send(message).hop(to: req.eventLoop)

New properties for `FCMAndroidNotification` (#18)

Choose a tag to compare

@MihaelIsaev MihaelIsaev released this 05 Jan 23:09

Thanks to @nerzh ❤️

Vapor 4 🚀

Choose a tag to compare

@MihaelIsaev MihaelIsaev released this 05 Jan 18:25

Please read the readme to get all the details