Skip to main content

Firebase Cloud Messaging

Firebase Cloud Messaging (FCM) is a service from firebase. Firebase is a platform that got acquired by Google and has a healthy and active community. Firebase Cloud Messaging (FCM) is a cross-platform messaging solution that lets you reliably send messages and can transfer a payload of up to 4000 bytes to a client app.

Setting up Firebase Project

For one to use FCM one needs a google account to login to the Firebase Console.

  1. After login to Firebase console, click “Getting started” where you will be taken to a page to create a project.

  2. Create a project that you will use to utilize Firebase by clicking create project:

    • Enter the name of project and accept Firebase terms
    • Select to enable or disable Google Analytics depending on your preference
    • Depending on your previous choice you will be prompted to go to your project, or to agree to terms for using Google Analytics then prompted to go to your project.
  3. Create a firebase app for either

    • android
    • ios
    • or both

    or both by adding both setup.

Android Firebase Setup

  • Click on the android icon below the statement Get started by adding firebase to your project.

  • Register app name by adding the android package name.

  • Download the google-services.json file and add the file to the project.

  • Add Firebase SDK to your project

    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

    ...
    }
    }
    • Continue to console.

IOS Firebase Setup

  • Click on the ios icon after selecting add app

  • Register app name by adding the iOS bundle ID.

  • Download the GoogleService-Info.plist file and add the file to the project.

    Config iOS Image
  • Add Firebase SDK to your project

    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.

  • Add initialisation code

    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;
    }

    Add APNs Certificate to Firebase Cloud Messaging

    In the Project Overview from the Firebase Console of your Project:

    • Read guide to obtain APNs Certificate. Skip this step if you already have one.
    • Go to Project Settings
    • Go to Cloud Messaging (Tab)
    • On iOS app configuration -> APNs Authentication Key -> Click Upload
Firebase Cert Upload
  • Add the Cerficate APNs you have generated

Getting App Keys and App Messenger Id

To obtain the Server Key and Sender Id. Go to:

  • On the side bar next to project overview there is a setting icon with a collapsible list.
  • Select Project setting
  • Select Cloud Messaging tab get the Server Key and Sender ID,
  • Copy the Server Key and Sender ID that you will use to configure BILDIT-CMS firebase push feature or setting up oneSignal account.