Skip to main content

Firebase Cloud Messaging

Setting up a Firebase account​

After signing in to the Google account, you need to set up a Firebase console following the steps below.

  • Go to the Firebase console website
  • In case you don't have any existing project you can create one by clicking Create a project else you can select the project you would like to use in your app. Below are the steps to follow when creating a new project:
    • Enter the project name
    • Read the terms of service for use of Firebase Services and accept them if you agree then click Continue
    • Enable Google Analytics for your Firebase project and then click Continue
    • Configure Google Analytics, you can either select the Default Account for Firebase or Create a new account. After selecting the account, click Create project
    • The loader for creating a project will begin. After finishing creating the project, the loader will close and it will display that the project is ready and afterwards click Continue
    • After this, you will be directed to the Firebase project

Adding Android or iOS app to the firebase project​

To set up the project for Android or iOS you would need to select the appropriate icon for the platform.

Select App

Android app​

  • Select the Android icon and a sheet will open up
  • Enter the Android package name (e.g. com.companyName.mobileAppName) then click Register app
  • Download the config file by clicking Download google-service.json which will be added to your mobile app. After you download the file click Next
  • Add Firebase SDK to your mobile app.

Project-level build.gradle (PROJECTNAME/build.gradle):

buildscript {
repositories {
// Check that you have the following line (if not, add it):
google() // Google's Maven repository

}
dependencies {
...
// Add this line
classpath 'com.google.gms:google-services:4.3.10'

}
}

allprojects {
...
repositories {
// Check that you have the following line (if not, add it):
google() // Google's Maven repository

...
}
}

Click on Next

  • Finish the steps by clicking Continue to the console
Add App

iOS app​

If you've already added an app, select + Add App or the iOS icon and a sheet will open to fill out the details.

  • Enter the Apple Bundle ID (e.g. com.companyName.mobileAppName) then click on Register app
  • Download the config file by clicking Download GoogleService-Info.plist which will be used on the mobile app and click Next
  • Add Firebase SDK to your mobile app.

Google services use CocoaPods to install and manage dependencies. Open a terminal window and navigate to the location of the Xcode project for your app.

Create a Podfile if you don't have one:

pod init

Open your Podfile and add:

# add pods for desired Firebase products
# https://firebase.google.com/docs/push-notifications/ios/setup#available-pods

Save the file and run:

pod install

This creates an .xcworkspace file for your app. Use this file for all future development on your application.

Click on Next

  • Add initialisation code to your mobile app.

To connect Firebase when your app starts up, add the initialisation code below to your AppDelegate.m file.

@import UIKit;
@import Firebase;

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[FIRApp configure];

return YES;
}

Click on Next

  • Finish the steps by clicking Continue to the console

Set up a Billing Account for Firebase​

In case you have not set up billing for your created project and you would wish to add an account select Spark plan next to the project name or select Upgrade on the bottom left of the Firebase console home page. It will open up a modal for selecting the billing.

  • Select Blaze Plan from the modal then click Continue, which will redirect you to set up your billing profile.
  • Select the country where your billing address is located then Confirm
  • Fill in the address details on the form and enter card details for the payment method
  • Select CONFIRM PURCHASE after filling all the details

Firebase Cloud Messaging​

To get the Sender ID and Server Key for sending notifications and using other cloud services:

Cloud messaging
  • Select Settings as shown in the image above then select Project setting
  • After navigating to Project settings select Cloud Messaging tab
  • Get the Server key and Sender ID to be used in the configuration for push notifications
  • For iOS, you require APNs Certificates. You would need to have an Apple Developer account to generate an APNs Certificate.
  • If you have a developer account and have generated a certificate, in the Apple App, select Upload
  • On the modal that opens, browse or drag the certificate, enter the Key ID and Team ID, then select Upload after filling all the details required.
  • After entering the details you can use the Server Key and Sender ID to use for cloud messaging.