Mobile SDK
Send push notifications to Android and iOS apps via Firebase Cloud Messaging (FCM). Notirix acts as a unified backend — one API for all platforms.
FCM Setup
Mobile push is powered by Firebase Cloud Messaging. You need a Firebase project and a service account key to connect it to Notirix.
Android
Add the Firebase SDK to your Android project, then register the FCM token with Notirix.
Dependencies
// app/build.gradle
dependencies {
implementation 'com.google.firebase:firebase-messaging:23.4.0'
}Register token
Call this once after the user opens the app (or after login if you want to attach a user ID):
import com.google.firebase.messaging.FirebaseMessaging
import okhttp3.*
import okhttp3.MediaType.Companion.toMediaType
import org.json.JSONObject
FirebaseMessaging.getInstance().token.addOnSuccessListener { token ->
val body = JSONObject().apply {
put("fcmToken", token)
put("platform", "android")
put("externalId", currentUserId) // optional — your user ID
}
val request = Request.Builder()
.url("https://push.notirix.com/api/apps/APP_ID/mobile/register")
.addHeader("X-API-Key", "YOUR_API_KEY")
.post(RequestBody.create("application/json".toMediaType(), body.toString()))
.build()
OkHttpClient().newCall(request).enqueue(/* callback */)
}externalId is your internal user identifier (e.g. database ID or email). Pass it to link the push token to a user so you can send targeted pushes via the API. Handle incoming messages
class MyFirebaseService : FirebaseMessagingService() {
override fun onMessageReceived(message: RemoteMessage) {
val title = message.notification?.title ?: message.data["title"] ?: return
val body = message.notification?.body ?: message.data["body"] ?: ""
val clickUrl = message.data["url"]
val intent = Intent(this, MainActivity::class.java).apply {
clickUrl?.let { putExtra("open_url", it) }
}
val pi = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_IMMUTABLE)
NotificationCompat.Builder(this, CHANNEL_ID)
.setSmallIcon(R.drawable.ic_notification)
.setContentTitle(title)
.setContentText(body)
.setContentIntent(pi)
.setAutoCancel(true)
.build()
.also { NotificationManagerCompat.from(this).notify(msgId, it) }
}
override fun onNewToken(token: String) {
// re-register when token rotates
registerWithNotirix(token)
}
}iOS
iOS push uses APNs under the hood. FCM bridges APNs → Notirix, so setup is the same on your backend. You only need to configure APNs inside Firebase.
APNs key in Firebase
Register token (Swift)
import FirebaseMessaging
import UserNotifications
func application(_ application: UIApplication,
didFinishLaunchingWithOptions opts: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .badge, .sound]) { _, _ in }
application.registerForRemoteNotifications()
Messaging.messaging().delegate = self
return true
}
extension AppDelegate: MessagingDelegate {
func messaging(_ messaging: Messaging, didReceiveRegistrationToken fcmToken: String?) {
guard let token = fcmToken else { return }
// POST to Notirix
var req = URLRequest(url: URL(string: "https://push.notirix.com/api/apps/APP_ID/mobile/register")!)
req.httpMethod = "POST"
req.setValue("application/json", forHTTPHeaderField: "Content-Type")
req.setValue("YOUR_API_KEY", forHTTPHeaderField: "X-API-Key")
req.httpBody = try? JSONSerialization.data(withJSONObject: [
"fcmToken": token,
"platform": "ios",
"externalId": currentUserId, // optional
])
URLSession.shared.dataTask(with: req).resume()
}
}Event tracking
Track delivery, opens, and custom events by sending events to the Notirix API. The Worker updates MessageDelivery records automatically for web push; for mobile you report events manually.
// Example: report "clicked" when user taps a notification
val deliveryId = message.data["deliveryId"] ?: return
val request = Request.Builder()
.url("https://push.notirix.com/api/mobile/events")
.addHeader("X-API-Key", "YOUR_API_KEY")
.post(RequestBody.create(
"application/json".toMediaType(),
JSONObject().apply {
put("deliveryId", deliveryId)
put("event", "clicked")
}.toString()
))
.build()
OkHttpClient().newCall(request).enqueue(/* callback */)deliveredFCM delivery receipt received (onMessageReceived)clickedUser taps the notificationdismissedUser swipes the notification away