LimitedRound 2 is open. Get your first month free, no extra charge.Join the waitlist ›
Wire in your backend

How to add Firebase Cloud Messaging to an iOS app

TL;DR. Firebase Cloud Messaging sends push notifications to an iOS app on top of Apple Push Notification service. You enable the push capability, request permission, register for remote notifications, and read the FCM token. The APNs auth key lives in the Firebase console server-side, never in the app. AppFlight enables the capability and wires the SDK in.

What Firebase Cloud Messaging does for an iOS app

FCM lets you send notifications to one device, a group, or a topic without running your own push infrastructure. On iOS it delivers through Apple Push Notification service, so it builds on the same system the OS uses. Each install gets a registration token, which you store on your backend to target that device later. You can send from the Firebase console for simple campaigns or from your server for transactional messages tied to events in your app. Permission is always the user's to grant, and Apple requires that your prompt makes sense for the feature.

Adding Firebase Cloud Messaging with AppFlight

Push needs two things: the Push Notifications capability on the app, and the APNs auth key uploaded to Firebase. In AppFlight you connect Firebase and enable push for the project. The GoogleService-Info.plist is a client file and ships in the app, while the APNs key is the secret and stays in the Firebase console server-side. AppFlight keeps that split, so no secret lands in the binary. You can then ask the AI to add the permission prompt, the registration code, and the delegate that captures the FCM token.

A SwiftUI example

Configure Firebase, request permission, and capture the FCM token through an app delegate:

import SwiftUI
import FirebaseCore
import FirebaseMessaging
import UserNotifications

final class AppDelegate: NSObject, UIApplicationDelegate, MessagingDelegate {
    func application(
        _ application: UIApplication,
        didFinishLaunchingWithOptions options: [UIApplication.LaunchOptionsKey: Any]? = nil
    ) -> Bool {
        FirebaseApp.configure()
        Messaging.messaging().delegate = self
        Task {
            let granted = try? await UNUserNotificationCenter.current()
                .requestAuthorization(options: [.alert, .badge, .sound])
            if granted == true {
                await MainActor.run { application.registerForRemoteNotifications() }
            }
        }
        return true
    }

    func application(
        _ application: UIApplication,
        didRegisterForRemoteNotificationsWithDeviceToken token: Data
    ) {
        Messaging.messaging().apnsToken = token
    }

    func messaging(_ messaging: Messaging, didReceiveRegistrationToken fcmToken: String?) {
        // Send this token to your server to target the device later.
        print("FCM token: \(fcmToken ?? "")")
    }
}

@main
struct MyApp: App {
    @UIApplicationDelegateAdaptor(AppDelegate.self) var delegate
    var body: some Scene {
        WindowGroup { ContentView() }
    }
}

Store the token on your backend in didReceiveRegistrationToken so you can push to the device when something relevant happens.

Alternatives

OneSignal wraps push with a dashboard, segmentation, and scheduling, which suits marketing-heavy notification flows without writing server code. Apple Push Notification service used directly, with no Firebase, is the leanest path when you already run a backend and want fewer dependencies. Firebase Cloud Messaging is the middle ground: free, cross-platform, and easy to send from a server, while still riding on APNs underneath.

FAQ

Does the APNs key go in the app?

No. The APNs authentication key is uploaded once to the Firebase console, where Firebase uses it server-side to talk to Apple Push Notification service. It is a secret and never ships in the binary. The app only holds the GoogleService-Info.plist, which is not secret.

What is the FCM registration token?

It is the address for one install of your app. You read it from Messaging.messaging() and send it to your server, which targets that device when it wants to push a message. The token can change, so refresh handling matters.

Do I still need APNs if I use FCM?

Yes. Firebase Cloud Messaging delivers iOS pushes through Apple Push Notification service, so you enable the push capability and provide the APNs key to Firebase. FCM is a layer on top of APNs, not a replacement for it.

Sources

Build this app without opening Xcode.

AppFlight turns a plain-English prompt into a real native iOS app and ships it to the App Store. Round 2 is open: free for your first month.

Join the waitlist