Skip to main content

Firebase Cloud Messaging

Setting up for 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
  • Incase you dont 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. The 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 the 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 will close and it will display that the project is ready and afterwards click Continue
    • After you will 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 aproppiate icon for the platform.

Select App

Android app

  • Select the android icon and a sheet will open up
  • Fill the Android package name eg. com.companyName.mobileAppName then click Register app
  • Download 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 you 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 have already added an app you can select app + Add App or/then select the iOS icon and sheet will open to fill out the details.

  • Fill the Apple Bundle ID eg. com.companyName.mobileAppName then click on Register app
  • Download 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

Setup a Billing Account for firebase

Incase you have not set up a billing to 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 select Continue which you will be redirected to set up your billing profile.
  • Select the country where your billing address is located then Confirm
  • Fill the address details on the form and then enter card details on the payment method
  • Select CONFIRM PURCHASE after filling all the details

Firebase Cloud messaging

To get to the cloud messaging so as to get the sender Id and Server Key to be used for sending notification and other cloud services.

Cloud messaging
  • Select setting as shown in the image above then select Project setting
  • After navigating to Project settings select Cloud Messanging tab
  • Get the Server key and Sender ID to be used in the configuration for push notification
  • For iOS, you require APNs Certificates. You would need to have Apple Developer account to generate an APNs Certificates.
  • If you have a developer account and have generated a certificate, on the Apple apps select Upload
  • On the modal that open, browze or drag the cerificate, Enter key ID and Enter team ID the 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 messanging.