Releases: MihaelIsaev/FCM
⚡️Swift 6 and async/await
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
Add image for the push notifications
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
- 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
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
// 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
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
- Go to Firebase Console -> Project Settings -> Cloud Messaging tab
- Copy
Server Key
fromProject Credentials
area
Next steps are optional
- Put server key into environment variables as
FCM_SERVER_KEY=<YOUR_SERVER_KEY>
- 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
- fix annoying warning: cannot modify client configuration after client has been used
- add
send
method with eventLoop argument to avoid manualhop(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)
Thanks to @nerzh ❤️
Vapor 4 🚀
Please read the readme to get all the details