Stay organized with collectionsSave and categorize content based on your preferences.
To get started withFCM, build out the simplest use case: sending a
test notification message from theNotifications composerto a development device
when the app is in the background on the device.
This page lists all the steps to achieve this, from setup to verification —
it may cover steps you already completed if you
haveset up an Apple client appforFCM.
If you don't already have an Xcode project and just want to try out a Firebase
product, you can download one of ourquickstart samples.
Create a Firebase project
Before you can add Firebase to your Apple app, you need to create a Firebase
project to connect to your app. VisitUnderstand Firebase Projectsto learn more about
Firebase projects.
To use Firebase in your Apple app, you need to register your app with your
Firebase project. Registering your app is often called "adding" your app to your
project.
ClickDownload GoogleService-Info.plistto obtain your app's
Firebase config file (GoogleService-Info.plist).
What do you need to know about this config file?
The Firebase config file contains unique, but non-secret identifiers for
your project and app. To learn more about this config file, visitUnderstand Firebase
Projects.
Make sure the config file name is not appended with additional characters,
like(2).
Move your config file into the root of your Xcode project. If prompted,
select to add the config file to all targets.
If you have multiple bundle IDs in your project, you must associate each bundle
ID with a registered app in theFirebaseconsole so that each app can have
its ownGoogleService-Info.plistfile.
Add Firebase SDKs to your app
Use Swift Package Manager to install and manage Firebase dependencies.
In Xcode, with your app project open, navigate toFile > Add Packages.
When prompted, add the Firebase Apple platforms SDK repository:
https://github.com/firebase/firebase-ios-sdk.git
Choose theFirebase Cloud Messaginglibrary.
Add the-ObjCflag to theOther Linker Flagssection of your target's build settings.
When finished, Xcode will automatically begin resolving and downloading your
dependencies in the background.
Upload your APNs authentication key
Upload your APNs authentication key to Firebase.
If you don't already have an APNs authentication key, make sure to create one in theApple Developer Member Center.
Inside your project in theFirebaseconsole, select the
gear icon, selectProject Settings, and then select theCloud Messagingtab.
InAPNs authentication keyunderiOS app configuration,
click theUploadbutton to upload your development authentication key, or
production authentication key, or both. At least one is required.
Browse to the location where you saved your key, select it, and clickOpen. Add the key ID for the key (available in theApple Developer Member Center) and clickUpload.
Initialize Firebase in your app
You'll need to add Firebase initialization code to your application. Import
the Firebase module and configure a shared instance as shown:
Import theFirebaseCoremodule in yourUIApplicationDelegate, as well as any otherFirebase modulesyour app delegate uses.
For example, to useCloud FirestoreandAuthentication:
Configure aFirebaseAppshared instance in your app delegate'sapplication(_:didFinishLaunchingWithOptions:)method:
SwiftUI
// Use Firebase library to configure APIsFirebaseApp.configure()
Swift
// Use Firebase library to configure APIsFirebaseApp.configure()
Objective-C
// Use Firebase library to configure APIs[FIRAppconfigure];
If you're using SwiftUI, you must create an application delegate and attach it
to yourAppstruct viaUIApplicationDelegateAdaptororNSApplicationDelegateAdaptor. You must also disable app delegate swizzling. For
more information, see theSwiftUI instructions.
SwiftUI
@mainstructYourApp:App{// register app delegate for Firebase setup@UIApplicationDelegateAdaptor(AppDelegate.self)vardelegatevarbody:someScene{WindowGroup{NavigationView{ContentView()}}}}
Register for remote notifications
Either at startup, or at the desired point in your application flow,
register your app for remote notifications. CallregisterForRemoteNotificationsas shown:
To send a message to a specific device, you need to know that device's
registration token. Because you'll need to enter the token in a field in theNotifications composerto complete this tutorial, make sure to copy the token
or securely store it after you retrieve it.
By default, theFCMSDK generates a
registration token for the client app instance on app launch.
Similar to the APNs device token, this token allows you to send targeted notifications
to any particular instance of your app.
In the same way that Apple platforms typically deliver an APNs device token on app start,
FCM provides a registration token viaFIRMessagingDelegate'smessaging:didReceiveRegistrationToken:method.
The FCM SDK retrieves a new or existing token during initial app launch and
whenever the token is updated or invalidated.
In all cases, the FCM SDK callsmessaging:didReceiveRegistrationToken:with a valid token.
The registration token may change when:
The app is restored on a new device
The user uninstalls/reinstall the app
The user clears app data.
Set the messaging delegate
To receive registration tokens, implement the messaging delegate
protocol and setFIRMessaging'sdelegateproperty after calling[FIRApp configure].
For example, if your application delegate conforms to the messaging delegate
protocol, you can set the delegate onapplication:didFinishLaunchingWithOptions:to itself.
Swift
Messaging.messaging().delegate=self
Objective-C
[FIRMessagingmessaging].delegate=self;
Fetching the current registration token
Registration tokens are delivered via the methodmessaging:didReceiveRegistrationToken:. This method is called generally once per
app start with registration token. When this method is called, it is the ideal time to:
If the registration token is new, send it to your application server.
Subscribe the registration token to topics. This is required only for
new subscriptions or for situations where the user has re-installed the app.
You can retrieve the token directly usingtoken(completion:).
A non null error is provided if the token retrieval failed in any way.
You can use this method at any time to access the token instead of storing
it.
Monitor token refresh
To be notified whenever the token is updated, supply a delegate conforming
to the messaging delegate protocol. The following example registers
the delegate and adds the proper delegate method:
Swift
funcmessaging(_messaging:Messaging,didReceiveRegistrationTokenfcmToken:String?){print("Firebase registration token:\(String(describing:fcmToken))")letdataDict:[String:String]=["token":fcmToken??""]NotificationCenter.default.post(name:Notification.Name("FCMToken"),object:nil,userInfo:dataDict)// TODO: If necessary send token to application server.// Note: This callback is fired at each app startup and whenever a new token is generated.}
-(void)messaging:(FIRMessaging*)messagingdidReceiveRegistrationToken:(NSString*)fcmToken{NSLog(@"FCM registration token: %@",fcmToken);// Notify about received token.NSDictionary*dataDict=[NSDictionarydictionaryWithObject:fcmTokenforKey:@"token"];[[NSNotificationCenterdefaultCenter]postNotificationName:@"FCMToken"object:niluserInfo:dataDict];// TODO: If necessary send token to application server.// Note: This callback is fired at each app startup and whenever a new token is generated.}
Alternatively, you can listen for anNSNotificationnamedkFIRMessagingRegistrationTokenRefreshNotificationrather than supplying a delegate method. The token property always has the
current token value.
Send a notification message
Install and run the app on the target device. On Apple devices, you'll need
to accept the request for permission to receive remote notifications.
Make sure the app is in the background on the device.
Otherwise, on theCampaignstab, selectNew campaignand thenNotifications.
Enter the message text. All other fields are optional.
SelectSend test messagefrom the right pane.
In the field labeledAdd an FCM registration token, enter the registration
token you obtained in a previous section of this guide.
SelectTest.
After you selectTest, the targeted client device (with the app in
the background) should receive the notification.
For insight into message delivery to your app, see
theFCMreporting dashboard, which records the
number of messages sent and opened on Apple and Android devices, along with
data for "impressions" (notifications seen by users) for Android apps.
Next steps
To go beyond notification messages and add other, more advanced behavior to your
app, see:
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-09-04 UTC."],[],[],null,[]]