Skip to main content

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​

CallWhat 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​

WhenCall
The member signs in, or the app starts with a restored sessionupdateToken
Firebase hands you a new token while a member is signed inupdateToken
The member turns push off in your appdeleteToken
Sign-outUsually nothing: logout() removes the registration

Example​

// 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)
}

Learn more​

  • API Reference for messaging().
  • Firebase and APNs setup, connecting your Firebase project to AIDE, and complete integration guides are in AIDE Docs.