mihaelisaev/fcm
It's a swift lib that gives ability to send push notifications through Firebase Cloud Messaging.
How to use
Preparation
- Go to Firebase Console -> Project Settings -> Cloud Messaging tab
- Copy
Server KeyfromProject Credentialsarea
Next steps are optional
- Put server key into environment variables as
FCM_SERVER_KEY=<YOUR_SERVER_KEY>(or put it intoserviceAccountKey.jsonfile asserver_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
let tokens = try await application.fcm.registerAPNS(.env, tokens: "token1", "token3", ..., "token100")
/// `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
let tokens = try await 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]
)
/// the same as in above example💡 Please note that push token taken from Xcode while debugging is for
sandbox, so either use.envSandboxor don't forget to setsandbox: true
Contributors
Thanks to these amazing people for their contributions:
- @ptoffy for enhancements in Swift 6 support #50
- @gennaro-safehill for Swift 6 and async/await support #48
- @paunik for adding image support in options #44
- @chinh-tran for retrieving subscribed topics #43
- @apemaia99 for supporting multiple configurations/clients #42
- @sroebert for removing unneeded setting of
ignoreUncleanSSLShutdown#36 - @sroebert for marking all
FCMAndroidConfigfields as optional #34 - @JCTec for Swift 5.2.1 support #33
- @Andrewangeta for reading service account from JSON string env variable #31
- @siemensikkema for batch messaging improvements #30
- @krezzoid for token issue decoding fix #27
- 💎 @grahamburgsma for fixing memory issues #26
- @geeksweep, @maximkrouk, @gustavoggs for README updates #22, #23, #37
- @emrahsifoglu for optional
priorityoption #20 - @nerzh for enhancements in
FCMAndroidNotification#16, #18 - @FredericRuaudel for multiple useful enhancements #13, #14, #15
- @grahamburgsma for
GoogleErrorandFCMError#10 - @simonmitchell for capability for silent
content-availablepush notifications #9 - @siemensikkema for updating to JWT
v3#3 - @pedantix for
APNSenhancements #2
Package Metadata
Repository: mihaelisaev/fcm
Default branch: master
README: README.md