React native firebase installation for IOS
After a long journey of research and troubleshooting, while trying to link my react native project to firebase on IOS, I decided to provide you with the proper solution which I struggled for a bit to achieve. I hope this will help you.
Once you have your firebase dependencies installed in your react native project and completed your firebase console project setup:
Make sure that you have added the GoogleService-Info.plist file to your project and that it's in the correct location (Your IOS root directory). This file contains the configuration information for your Firebase project.
configuring the Firebase SDK in your AppDelegate file is an important step in linking Firebase to your React Native iOS project.
The AppDelegate file is the entry point for your iOS app, and it’s responsible for handling various application-level events, such as application launch and background/foreground transitions. In order to use Firebase in your app, you will need to configure the Firebase SDK in the AppDelegate file by importing the Firebase headers and making sure that the AppDelegate class conforms to the necessary Firebase protocols.
Here are the general steps to configure Firebase SDK in your AppDelegate file:
Get Khaled Agbaria’s stories in your inbox
Join Medium for free to get updates from this writer.
Import the Firebase headers in your AppDelegate.h file:
#import <Firebase.h>In the AppDelegate.mm file, you need to call the FIRApp.configure() in the didFinishLaunchingWithOptions method.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Configure Firebase
[FIRApp configure];
return YES;
}By configuring the Firebase SDK in your AppDelegate file, you are making the Firebase functionality available to the rest of your app, and you can use Firebase services in your iOS code.
Firebase is also a native iOS SDK and requires the Firebase iOS frameworks and dependencies to be installed in your iOS project. To install the Firebase iOS frameworks and dependencies, you will need to use CocoaPods to install the Firebase pods in your iOS project. So your Podfile may look like this:
require_relative '../node_modules/react-native/scripts/react_native_pods'
require_relative '../node_modules/@react-native-community/cli-platform-ios/native_modules'
$RNFirebaseAsStaticFramework = true
platform :ios, '12.4'
install! 'cocoapods', :deterministic_uuids => false
use_frameworks! :linkage => :static
target 'zaater' do
config = use_native_modules!
#Installing pods
pod 'Firebase/Core'
pod 'Firebase/Auth'
pod 'Firebase/Firestore'
pod 'Firebase/Storage'
# Flags change depending on the env values.xx
flags = get_default_flags()
use_react_native!(
:path => config[:reactNativePath],
# Hermes is now enabled by default. Disable by setting this flag to false.
# Upcoming versions of React Native may rely on get_default_flags(), but
# we make it explicit here to aid in the React Native upgrade process.
:hermes_enabled => true,
:fabric_enabled => flags[:fabric_enabled],
# Enables Flipper.
#
# Note that if you have use_frameworks! enabled, Flipper will not work and
# you should disable the next line.
# :flipper_configuration => FlipperConfiguration.enabled,
# An absolute path to your application root.
:app_path => "#{Pod::Config.instance.installation_root}/.."
)
target 'zaaterTests' do
inherit! :complete
# Pods for testing
end
post_install do |installer|
react_native_post_install(
installer,
# Set `mac_catalyst_enabled` to `true` in order to apply patches
# necessary for Mac Catalyst builds
:mac_catalyst_enabled => false
)
__apply_Xcode_12_5_M1_post_install_workaround(installer)
end
end$RNFirebaseAsStaticFramework is a flag that can be used in a Podfile to specify whether the Firebase libraries should be linked as static frameworks or dynamic frameworks. When this flag is set to true, the Firebase libraries will be linked as static frameworks, which means that the libraries will be included in the binary of the app. When this flag is set to false, the Firebase libraries will be linked as dynamic frameworks, which means that the libraries will not be included in the binary of the app but will be loaded at runtime.
This flag is commonly used when integrating Firebase with React Native projects, as it allows you to link the Firebase libraries as static frameworks, which can help to prevent issues that can occur when linking dynamic frameworks with React Native.
Dont forget to navigate to your IOS project directory and run:
pod install --repo-update







