success!!

Google’s new Cloud Functions service for Firebase is a huge addition to their offerings, and I’ve been focused on utilizing it for one feature in particular: serverless push notifications. I started working on a basic social networking app a few weeks ago, and from the onset implementing notifications was a definitive goal (quite honestly it was the purpose of the project). However, I did not want to go through the trouble of setting up a server in order to listen to my Firebase data. Luckily for me, with some basic knowledge of how to use Firebase SDKs, push notifications became quick and easy.

Setting up push notifications — even with this implementation — can be daunting, especially given the amount of set-up that is required. To follow my implementation, three Firebase services must be utilized:

Firebase Authentication (technically optional) Firestore or Realtime Database Firebase Cloud Messaging (FCM) Firebase Cloud Functions

Setting Up Firebase with RNF:

Unfortunately, Google’s documentation for React Native users is fairly limited, and even the most popular integration packages skimp on thorough instructions, and have inconsistent features. I opted to use React Native Firebase (RNF). Luckily, their installation procedure is straightforward and well described.

Install node module, then link the dependency.

$ npm install --save react-native-firebase $ react-native link react-native-firebase

Create a Firebase project in the console, download the GoogleService-Info.plist and move it to: ios/[YOUR APP NAME] so the SDK can connect to your project. Open the project with XCode to ensure the file has been added properly. If it doesn’t show up in the sidebar, just drag the file in.

Then, open AppDelegate.m and add:

#import <Firebase.h>

As well as:

[FIRApp configure];

at the beginning of the didFinishLaunchingWithOptions:(NSDictionary * )launchOptions method.

Set up CocoaPods.

Generate a Podfile.

Sometimes the Podfile generates with duplicate declarations, copy and paste the following into yours if errors are reported:

# Uncomment the next line to define a global platform for your project

platform :ios, '9.0' target '[YOUR APP NAME]' do

# Uncomment the next line if you're using Swift or would like to use dynamic frameworks

# use_frameworks! # Pods for Sesh

pod 'Firebase/Core'

pod 'Firebase/Firestore'

pod 'Firebase/Messaging' target 'Sesh-tvOSTests' do

inherit! :search_paths

# Pods for testing

end target 'SeshTests' do

inherit! :search_paths

# Pods for testing

end end

Run:

$ pod install

If any issues are encountered, refer to here.

I’m going to assume you already have a working application built with a backend database to save time — don’t worry, there are plenty of guides on how to do this, check out the docs here. At the very least, for directed push notifications, your database must store unique push tokens for each user, and presumably some data to send them.