Stay organized with collectionsSave and categorize content based on your preferences.
This quickstart describes how to set upFirebase Cloud Messagingin your
mobile and web client apps so that you can reliably send messages. For server
environments, seeYour server environment andFCM.
Set up aFirebase Cloud Messagingclient app with Unity
To write your cross-platformFirebase Cloud Messagingclient app with Unity, use
theFirebase Cloud MessagingAPI. The Unity SDK works for
both Android and Apple, with some additional setup required for each platform.
Before you begin
Prerequisites
Install Unity 2021 LTS or later. Support for Unity 2020 is considered
deprecated, and will no longer be actively supported after the next major
release. Earlier versions may also be compatible but won't be actively
supported.
(Apple platforms only)Install the following:
Xcode 13.3.1 or higher
CocoaPods 1.12.0 or higher
Make sure that your Unity project meets these requirements:
For iOS— targets iOS 13 or higher
For tvOS- targets tvOS 13 or higher
For Android— targets API level 21
(Lollipop) or higher
Set up a device or use an emulator to run your Unity project.
For iOS or tvOS— Set up aphysical deviceto run your
app, and complete these tasks:
If you don't already have a Unity project and just want to try out a Firebase
product, you can download one of ourquickstart samples.
Step 1: Create a Firebase project
Before you can add Firebase to your Unity project, you need to create a Firebase
project to connect to your Unity project. VisitUnderstand Firebase
Projectsto learn more about Firebase projects.
In the center of the project overview page, click theUnityicon
(plat_unity)
to launch the setup workflow.
If you've already added an app to your Firebase project, clickAdd appto display the platform options.
Select which build target of your Unity project that you’d like to register,
or you can even select to register both targets now at the same time.
Enter your Unity project’s platform-specific ID(s).
For iOS— Enter your Unity project’s iOS ID in theiOS bundle
IDfield.
For Android— Enter your Unity project’s Android ID in theAndroid package
namefield. The termspackage nameandapplication IDare often used
interchangeably.
Where do you find your Unity project's ID?
Open your Unity project in your Unity IDE, then navigate to the settings
section for each platform:
For iOS— Navigate toBuild Settings > iOS.
For Android— Navigate toAndroid > Player Settings >
Other Settings.
Your Unity project's ID is theBundle Identifiervalue
(example ID:com.yourcompany.yourproject).
(Optional)Enter your Unity project’s platform-specific nickname(s). These nicknames are internal, convenience identifiers and are only visible
to you in theFirebaseconsole.
ClickRegister app.
Step 3: Add Firebase configuration files
Obtain your platform-specific Firebase configuration file(s) in theFirebaseconsole setup workflow.
For iOS— ClickDownload GoogleService-Info.plist.
For Android— ClickDownload google-services.json.
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.
For an optimal experience withFirebase Cloud Messaging, we recommendenablingGoogle Analyticsin your project. Also, as part of setting upAnalytics, you need to add
the Firebase package forAnalyticsto your app.
Analyticsenabled
Add the Firebase package forGoogle Analytics:FirebaseAnalytics.unitypackage
Add the package forFirebase Cloud Messaging:FirebaseMessaging.unitypackage
Analyticsnot enabled
Add the package forFirebase Cloud Messaging:FirebaseMessaging.unitypackage
In theImport Unity Packagewindow, clickImport.
Back in theFirebaseconsole, in the setup workflow, clickNext.
Step 5: Confirm Google Play services version requirements
Add the followingusingstatement and initialization code at the start of your
application. You can check for and optionally updateGoogle Playservicesto the
required version before calling any other methods in the SDK.
usingFirebase.Extensions;
Firebase.FirebaseApp.CheckAndFixDependenciesAsync().ContinueWithOnMainThread(task=>{vardependencyStatus=task.Result;if(dependencyStatus==Firebase.DependencyStatus.Available){// Create and hold a reference to your FirebaseApp,// where app is a Firebase.FirebaseApp property of your application class.app=Firebase.FirebaseApp.DefaultInstance;// Set a flag here to indicate whether Firebase is ready to use by your app.}else{UnityEngine.Debug.LogError(System.String.Format("Could not resolve all Firebase dependencies: {0}",dependencyStatus));//FirebaseUnitySDK is not safe to use here.}});
Your Unity project is registered and configured to use Firebase.
Get setup with Apple platforms
Use the following instructions to set upFCMwith Unity and Apple
platforms.
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.
Enable push notifications on Apple platforms
Click your project in Xcode, then select theGeneraltab from theEditor area.
Scroll toLinked Frameworks and Libraries, then click the+button to add a framework.
In the window that appears, scroll toUserNotifications.framework, click
that entry, then clickAdd.
Click your project in Xcode, then select theCapabilitiestab from theEditor area.
The Firebase Cloud Message library will be initialized when adding handlers
for either theTokenReceivedorMessageReceivedevents.
Upon initialization, a registration token is requested for the client app
instance. The app will receive the token with theOnTokenReceivedevent,
which should be cached for later use. You'll need this
token if you want to target this specific device for messages.
In addition, you will need to register for theOnMessageReceivedevent if
you want to be able to receive incoming messages.
Use the following instructions to setupFCMwith Unity and Android
platforms.
Configure an Android entry point Activity
Firebase Cloud Messagingcomes bundled with a custom entry point
activity that replaces the defaultUnityPlayerActivity. If you are not using
a custom entry point, this replacement happens automatically and you shouldn't
have to take any additional action.
TheFirebase Cloud MessagingUnity Plugin on Android comes bundled with two
additional files:
Assets/Plugins/Android/libmessaging_unity_player_activity.jarcontains an
activity calledMessagingUnityPlayerActivitythat replaces the standardUnityPlayerActivity.
Assets/Plugins/Android/AndroidManifest.xmlinstructs the app to useMessagingUnityPlayerActivityas the entry point to the app.
These files are provided because the defaultUnityPlayerActivitydoes not
handleonStop,onRestartactivity lifecycle transitions or implement theonNewIntentwhich is necessary forFirebase Cloud Messagingto correctly
handle incoming messages.
Configure a custom entry point Activity
If your app does not use the defaultUnityPlayerActivityyou will need to
remove the suppliedAndroidManifest.xmland make sure that your custom
activity properly handles all transitions of theAndroid Activity
Lifecycle(an example of how to do this is shown below). If your custom activity extendsUnityPlayerActivityyou can instead extendcom.google.firebase.MessagingUnityPlayerActivitywhich implements all
necessary methods.
If you are using a custom Activity and not extendingcom.google.firebase.MessagingUnityPlayerActivity, you should include the
following snippets in your Activity.
/*** Workaround for when a message is sent containing both a Data and Notification payload.** When the app is in the background, if a message with both a data and notification payload is* received the data payload is stored on the Intent passed to onNewIntent. By default, that* intent does not get set as the Intent that started the app, so when the app comes back online* it doesn't see a new FCM message to respond to. As a workaround, we override onNewIntent so* that it sends the intent to the MessageForwardingService which forwards the message to the* FirebaseMessagingService which in turn sends the message to the application.*/@OverrideprotectedvoidonNewIntent(Intentintent){Intentmessage=newIntent(this,MessageForwardingService.class);message.setAction(MessageForwardingService.ACTION_REMOTE_INTENT);message.putExtras(intent);message.setData(intent.getData());//ForearlierversionsofFirebaseC++SDK(<7.1.0),use`startService`.//startService(message);MessageForwardingService.enqueueWork(this,message);}/*** Dispose of the mUnityPlayer when restarting the app.** This makes sure that when the app starts up again it does not start with stale data.*/@OverrideprotectedvoidonCreate(BundlesavedInstanceState){if(mUnityPlayer!=null){mUnityPlayer.quit();mUnityPlayer=null;}super.onCreate(savedInstanceState);}
New versions of Firebase C++ SDK (7.1.0 onwards) useJobIntentServicewhich
requires additional modifications inAndroidManifest.xmlfile.
When the app is not running at all and a user taps on a notification,
the message is not, by default, routed throughFCM's built in
callbacks. In this case, message payloads are received through anIntentused to start the application.
Messages received while the app is in the background have the content of their
notification field used to populate the system tray notification, but that
notification content won't be communicated toFCM. This means thatFirebaseMessage.Notificationwill be a null.
Notification: system tray Data: in extras of the intent.
Handling messages with deep links on Android
FCMallows messages to be sent containing a deep link into your app.
To receive messages that contain a deep link, you must add a new intent filter
to the activity that handles deep links for your app. The intent filter should
catch deep links of your domain. In AndroidManifest.xml:
When users tap a notification containing a link to the scheme and host you
specify, your app will start the activity with this intent filter to handle the
link.
Prevent auto initialization
FCMgenerates a registration token for device targeting.
When a token is generated, the library uploads the
identifier and configuration data to Firebase. If you want to get an explicit
opt-in before using the token, you can prevent generation at configure time by
disabling FCM (and on Android, Analytics). You can add a metadata value to
yourInfo.plist(not yourGoogleService-Info.plist) on Apple, or yourAndroidManifest.xmlon Android:
[[["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,[]]