Push Notifications
AFCore sends push notifications to members through Firebase Cloud Messaging (FCM), which uses APNs on iOS. Your app owns Firebase and shows the notifications; AFCore only keeps track of which install belongs to which member, so the backend can reach the right device.
What you can do
- Register this install's FCM token for the signed-in member, so the backend can send to it.
- Remove the registration when the member turns push off.
- Rely on sign-out:
logout()removes this install's registration before it ends the session. - Route the deep link a notification carries the same way you route other in-app links.
Key APIs
| Call | What it is for |
|---|---|
messaging().updateToken(token, deviceId) | Register the FCM token for the signed-in member |
messaging().deleteToken(deviceId) | Remove this install's registration |
AFPermissions.requestPermission(Permission.NOTIFICATIONS) | Ask to show notifications |
deviceId is your own identifier for the install: generate it once (a UUID, for example) and keep it, so each install has its own registration.
When to register and remove the token
| When | Call |
|---|---|
| The member signs in, or the app starts with a restored session | updateToken |
| Firebase hands you a new token while a member is signed in | updateToken |
| The member turns push off in your app | deleteToken |
| Sign-out | Usually nothing: logout() removes the registration |
Example
- Android (Kotlin)
- iOS (Swift)
// After sign-in, and whenever Firebase rotates the token
lifecycleScope.launch {
val token = FirebaseMessaging.getInstance().token.await()
AFCore.messaging().updateToken(token = token, deviceId = installId)
}
// The member turns push off in your settings
lifecycleScope.launch {
AFCore.messaging().deleteToken(deviceId = installId)
}
// After sign-in, and whenever Firebase reports a new FCM token
Task {
_ = try await AFCore.shared.messaging().updateToken(token: fcmToken, deviceId: installId)
}
// The member turns push off in your settings
Task {
_ = try await AFCore.shared.messaging().deleteToken(deviceId: installId)
}
Learn more
- API Reference for
messaging(). - Firebase and APNs setup, connecting your Firebase project to AIDE, and complete integration guides are in AIDE Docs.