Closed HainesR11 closed 1 year ago
Hi @HainesR11 it looks like you didn't add [FIRApp configure]
to your AppDelegate.m
try again after adding this and don't forget to add #import <Firebase.h>
to top of your file.
docs: https://rnfirebase.io/#configure-firebase-with-ios-credentials
Hello ๐, to help manage issues we automatically close stale issues.
This issue has been automatically marked as stale because it has not had activity for quite some time.Has this issue been fixed, or does it still require attention?
This issue will be closed in 15 days if no further activity occurs.
Thank you for your contributions.
same problem here for Android and IOS: No Firebase App '[DEFAULT]' has been created - call firebase.initializeApp()
@gabrrielsilva Can you share your code how you implemented it?
I couldn't find the import
statement to call firebase.initializeApp()
Hello ๐, to help manage issues we automatically close stale issues.
This issue has been automatically marked as stale because it has not had activity for quite some time.Has this issue been fixed, or does it still require attention?
This issue will be closed in 15 days if no further activity occurs.
Thank you for your contributions.
Same issue on my end
same issue
the same issue on Android keeps giving the error Error: No Firebase App '[DEFAULT]' has been created
even though I already added [FIRApp configure] in AppDelegate.m
but in android what is missing?
how did u solve that, same issue here
I have to say, either documentation is poor or I'm blind but I didn't find anything regarding initializeApp
on the docs. I've got back to RN after 2 years and got confused.
"react-native": "^0.73.0",
"@react-native-firebase/analytics": "^18.7.2",
"@react-native-firebase/app": "^18.7.2",
"@react-native-firebase/messaging": "^18.7.2",
Solution:
iOS - You must enable fetch
and remote-notification
# Info.plist
<key>UIBackgroundModes</key>
<array>
<string>fetch</string>
<string>remote-notification</string>
</array>
#ย AppDelete.mm
#import <Firebase.h>
...
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
...
[FIRApp configure];
...
}
Android - You must initialise before using/calling anything from firebase
// index.js or App.js
import React, {useEffect, useState} from 'react';
import firebase from '@react-native-firebase/app';
const Comp = () => {
const [loading, setLoading] = useState(true);
useEffect(() => {
const register = async () => {
const firebaseConfig = {
apiKey: '...',
authDomain: '...',
projectId: '...',
storageBucket: '...',
messagingSenderId: '...',
appId: '...',
databaseURL: '...',
};
firebase
.initializeApp(firebaseConfig)
.then(() => {
registerBackgroundMessage();
setLoading(false);
})
.catch(error => {
setLoading(false);
});
};
if (!firebase.apps.length) {
register();
} else {
registerBackgroundMessage();
}
}, []);
// Register background handler
const registerBackgroundMessage = () => {
messaging().setBackgroundMessageHandler(async remoteMessage => {
console.log('Message handled in the background!', remoteMessage);
});
};
return <Provider>{!loading && <App />}</Provider>;
};
AppRegistry.registerComponent(appName, () => Comp);
The DEFAULT
app will be initialized for you automatically if auto-linking is not broken in your react-native app for Android. On iOS it is done with auto-linking and the [FIRApp configure]
line in your AppDelegate file as instructed in rnfirebase.io install docs
There is no need to directly call initializeApp
assuming those things are working and you have google-services.json and GoogleServices-Info.plist in your project
The only time most people ever consider using intiializeApp is if they want something very specific and rarely used: secondary apps in the modules that support secondary apps
If this is for your primary app, I would look through your react-native auto-linking configuration and make sure the json/plist files for google services are in the project and in the right spot.
The
DEFAULT
app will be initialized for you automatically if auto-linking is not broken in your react-native app for Android. On iOS it is done with auto-linking and the[FIRApp configure]
line in your AppDelegate file as instructed in rnfirebase.io install docsThere is no need to directly call
initializeApp
assuming those things are working and you have google-services.json and GoogleServices-Info.plist in your projectThe only time most people ever consider using intiializeApp is if they want something very specific and rarely used: secondary apps in the modules that support secondary apps
If this is for your primary app, I would look through your react-native auto-linking configuration and make sure the json/plist files for google services are in the project and in the right spot.
Autolinking is perfectly fine in my case - at least with every other module I'm using. Btw, I'm getting that error on both iOS and Android. I'm also getting You must be registered for remote messages before calling getToken
warning even though I've set firebase.json
in project root with "messaging_ios_auto_register_for_remote_messages": true
.
Issue
Describe your issue here
Currently trying to implement
react-native-firebase
to my app. I've managed to get android working and it returning the correct response.However when it come to iOS i keep getting a console.warning saying:
Project Files
Javascript
Click To Expand
#### `package.json`: ```json { "name": "devex", "version": "0.0.1", "private": true, "scripts": { "android": "react-native run-android", "ios": "react-native run-ios", "start": "react-native start", "test": "jest", "lint": "eslint . --ext .js,.jsx,.ts,.tsx" }, "dependencies": { "@react-native-firebase/app": "16.7", "@react-native-firebase/remote-config": "16.7", "@react-navigation/native": "^6.1.6", "@react-navigation/stack": "^6.3.16", "@shopify/restyle": "^2.4.2", "eslint-plugin-simple-import-sort": "^10.0.0", "react": "18.1.0", "react-native": "0.70.8", "react-native-gesture-handler": "^2.9.0", "react-native-reanimated": "^3.0.2", "react-native-safe-area-context": "^4.5.0", "react-native-screens": "^3.20.0" }, "devDependencies": { "@babel/core": "^7.12.9", "@babel/runtime": "^7.12.5", "@react-native-community/eslint-config": "^2.0.0", "@tsconfig/react-native": "^2.0.2", "@types/jest": "^26.0.23", "@types/react": "^18.0.21", "@types/react-native": "^0.70.6", "@types/react-test-renderer": "^18.0.0", "@typescript-eslint/eslint-plugin": "^5.37.0", "@typescript-eslint/parser": "^5.37.0", "babel-jest": "^26.6.3", "eslint": "^7.32.0", "jest": "^26.6.3", "metro-react-native-babel-preset": "0.72.3", "react-test-renderer": "18.1.0", "typescript": "^4.8.3" }, "jest": { "preset": "react-native", "moduleFileExtensions": [ "ts", "tsx", "js", "jsx", "json", "node" ] } } ``` #### `firebase.json` for react-native-firebase v6: ```json export const fetchFirebase = async () => { await remoteConfig().setConfigSettings({ minimumFetchIntervalMillis: 30000, }); await remoteConfig() .setDefaults(firebaseDefaults) .then(() => remoteConfig() .fetchAndActivate() .then(active => console.log('firebase active - ', active)) .catch(error => console.log('error - ', error)), ) .catch(error => console.log('error - ', error)); }; ```
iOS
Click To Expand
#### `ios/Podfile`: - [ ] I'm not using Pods - [x] I'm using Pods and my Podfile looks like: ```ruby 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 pod 'FirebaseRemoteConfig' use_frameworks! :linkage => :static target 'devex' do config = use_native_modules! # Flags change depending on the env values. 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 'devexTests' 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 ``` #### `AppDelegate.m`: ```objc #import "AppDelegate.h" #import
#import
#import
#import
#if RCT_NEW_ARCH_ENABLED
#import
#import
#import
#import
#import
#import
#import
static NSString *const kRNConcurrentRoot = @"concurrentRoot";
@interface AppDelegate () {
RCTTurboModuleManager *_turboModuleManager;
RCTSurfacePresenterBridgeAdapter *_bridgeAdapter;
std::shared_ptr _reactNativeConfig;
facebook::react::ContextContainer::Shared _contextContainer;
}
@end
#endif
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
RCTAppSetupPrepareApp(application);
RCTBridge *bridge = [[RCTBridge alloc] initWithDelegate:self launchOptions:launchOptions];
#if RCT_NEW_ARCH_ENABLED
_contextContainer = std::make_shared();
_reactNativeConfig = std::make_shared();
_contextContainer->insert("ReactNativeConfig", _reactNativeConfig);
_bridgeAdapter = [[RCTSurfacePresenterBridgeAdapter alloc] initWithBridge:bridge contextContainer:_contextContainer];
bridge.surfacePresenter = _bridgeAdapter.surfacePresenter;
#endif
NSDictionary *initProps = [self prepareInitialProps];
UIView *rootView = RCTAppSetupDefaultRootView(bridge, @"devex", initProps);
if (@available(iOS 13.0, *)) {
rootView.backgroundColor = [UIColor systemBackgroundColor];
} else {
rootView.backgroundColor = [UIColor whiteColor];
}
self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
UIViewController *rootViewController = [UIViewController new];
rootViewController.view = rootView;
self.window.rootViewController = rootViewController;
[self.window makeKeyAndVisible];
return YES;
}
/// This method controls whether the `concurrentRoot`feature of React18 is turned on or off.
///
/// @see: https://reactjs.org/blog/2022/03/29/react-v18.html
/// @note: This requires to be rendering on Fabric (i.e. on the New Architecture).
/// @return: `true` if the `concurrentRoot` feture is enabled. Otherwise, it returns `false`.
- (BOOL)concurrentRootEnabled
{
// Switch this bool to turn on and off the concurrent root
return true;
}
- (NSDictionary *)prepareInitialProps
{
NSMutableDictionary *initProps = [NSMutableDictionary new];
#ifdef RCT_NEW_ARCH_ENABLED
initProps[kRNConcurrentRoot] = @([self concurrentRootEnabled]);
#endif
return initProps;
}
- (NSURL *)sourceURLForBridge:(RCTBridge *)bridge
{
#if DEBUG
return [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index"];
#else
return [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"];
#endif
}
#if RCT_NEW_ARCH_ENABLED
#pragma mark - RCTCxxBridgeDelegate
- (std::unique_ptr)jsExecutorFactoryForBridge:(RCTBridge *)bridge
{
_turboModuleManager = [[RCTTurboModuleManager alloc] initWithBridge:bridge
delegate:self
jsInvoker:bridge.jsCallInvoker];
return RCTAppSetupDefaultJsExecutorFactory(bridge, _turboModuleManager);
}
#pragma mark RCTTurboModuleManagerDelegate
- (Class)getModuleClassFromName:(const char *)name
{
return RCTCoreModulesClassProvider(name);
}
- (std::shared_ptr)getTurboModule:(const std::string &)name
jsInvoker:(std::shared_ptr)jsInvoker
{
return nullptr;
}
- (std::shared_ptr)getTurboModule:(const std::string &)name
initParams:
(const facebook::react::ObjCTurboModule::InitParams &)params
{
return nullptr;
}
- (id)getModuleInstanceFromClass:(Class)moduleClass
{
return RCTAppSetupDefaultModuleFromClass(moduleClass);
}
#endif
@end
```
Android
Click To Expand
#### Have you converted to AndroidX? - [ ] my application is an AndroidX application? - [ ] I am using `android/gradle.settings` `jetifier=true` for Android compatibility? - [ ] I am using the NPM package `jetifier` for react-native compatibility? #### `android/build.gradle`: ```groovy // N/A ``` #### `android/app/build.gradle`: ```groovy // N/A ``` #### `android/settings.gradle`: ```groovy // N/A ``` #### `MainApplication.java`: ```java // N/A ``` #### `AndroidManifest.xml`: ```xml ```
Environment
Click To Expand
**`react-native info` output:** ``` System: OS: macOS 13.3.1 CPU: (10) arm64 Apple M1 Pro Memory: 91.28 MB / 32.00 GB Shell: 5.9 - /bin/zsh Binaries: Node: 18.9.0 - ~/.nvm/versions/node/v18.9.0/bin/node Yarn: 1.22.19 - /opt/homebrew/bin/yarn npm: 9.1.3 - ~/.nvm/versions/node/v18.9.0/bin/npm Watchman: 2023.01.16.00 - /opt/homebrew/bin/watchman Managers: CocoaPods: 1.12.0 - /opt/homebrew/bin/pod SDKs: iOS SDK: Platforms: DriverKit 22.4, iOS 16.4, macOS 13.3, tvOS 16.4, watchOS 9.4 Android SDK: Not Found IDEs: Android Studio: 2021.3 AI-213.7172.25.2113.9123335 Xcode: 14.3/14E222b - /usr/bin/xcodebuild Languages: Java: 11.0.7 - /usr/bin/javac npmPackages: @react-native-community/cli: Not Found react: 18.1.0 => 18.1.0 react-native: 0.70.8 => 0.70.8 react-native-macos: Not Found npmGlobalPackages: *react-native*: Not Found ``` - **Platform that you're experiencing the issue on**: - [x] iOS - [ ] Android - [ ] **iOS** but have not tested behavior on Android - [ ] **Android** but have not tested behavior on iOS - [ ] Both - **`react-native-firebase` version you're using that has this issue:** - `16.7.0` - **`Firebase` module(s) you're using that has the issue:** - `@react-native-firebase/app` - `@react-native-firebase/remote-config` - **Are you using `TypeScript`?** - `Y` & `4.8.3`
React Native Firebase
andInvertase
on Twitter for updates on the library.