Quantcast
Channel: Active questions tagged react-native+ios - Stack Overflow
Viewing all articles
Browse latest Browse all 16750

'FirebaseApp instance may not be nil. Use FirebaseApp.app() if you'd like to use the default FirebaseApp instance.' Second app in react native for iOS

$
0
0

So, I worked on my react native app while running android emulators for a while, and during that time, I had initialized a second firebase app using @react-native-firebase/app other than my main one which is working fine on both android and iOS. I was fully capable of using the second app I had initialized, but then I began to run it on an iOS simulator and that's when things went downward and I got this error: FirebaseApp instance may not be nil. Use FirebaseApp.app() if you'd like to use the default FirebaseApp instance. whenever I tried to fetch a document and I still haven't been able to fix. I tried logging the second app using console.log(firebase.app('appName') and it would show me all the correct methods and variables so it wasn't undefined. I don't want to add another Google-services.plist file, since that would mess up my analytics. does anyone have any idea as to how I could solve this?

Here's where I initialize my second app:

import auth from '@react-native-firebase/auth';import analytics from '@react-native-firebase/analytics';import storage from '@react-native-firebase/storage';import firestore from '@react-native-firebase/firestore';import GlobalHandler from '../GlobalHandler/GlobalHandler';import {EmptyAvatar} from '../Image Requires/imageImports';import {showMessage} from 'react-native-flash-message';import { LocalNotification } from '../PushNotifications/PushNotifications';const secondApp = app.initializeApp(  {    apiKey: 'MY_API_KEY',    authDomain: 'MY_PROJECT.firebaseapp.com',    databaseURL: 'https://MY_PROJECT.firebaseio.com',    projectId: 'MY_PROJECT',    storageBucket: 'MY_PROJECT.appspot.com',    messagingSenderId: 'MESSAGING_SENDER_ID',    appId: 'MY_APP_ID',    measurementId: 'MEASUREMENT_ID',  },  {name: 'second'},);

And when I use it for example here: console.log((await firestore(app.app('second')).collection('users').doc(DOC_ID).get()).data())The error above is thrown.

Here's my podfile:

platform :ios, '9.0'require_relative '../node_modules/@react-native-community/cli-platform-ios/native_modules'def add_flipper_pods!(versions = {})  versions['Flipper'] ||= '~> 0.33.1'  versions['DoubleConversion'] ||= '1.1.7'  versions['Flipper-Folly'] ||= '~> 2.1'  versions['Flipper-Glog'] ||= '0.3.6'  versions['Flipper-PeerTalk'] ||= '~> 0.0.4'  versions['Flipper-RSocket'] ||= '~> 1.0'  pod 'FlipperKit', versions['Flipper'], :configuration => 'Debug'  pod 'FlipperKit/FlipperKitLayoutPlugin', versions['Flipper'], :configuration => 'Debug'  pod 'FlipperKit/SKIOSNetworkPlugin', versions['Flipper'], :configuration => 'Debug'  pod 'FlipperKit/FlipperKitUserDefaultsPlugin', versions['Flipper'], :configuration => 'Debug'  pod 'FlipperKit/FlipperKitReactPlugin', versions['Flipper'], :configuration => 'Debug'  # List all transitive dependencies for FlipperKit pods  # to avoid them being linked in Release builds  pod 'Flipper', versions['Flipper'], :configuration => 'Debug'  pod 'Flipper-DoubleConversion', versions['DoubleConversion'], :configuration => 'Debug'  pod 'Flipper-Folly', versions['Flipper-Folly'], :configuration => 'Debug'  pod 'Flipper-Glog', versions['Flipper-Glog'], :configuration => 'Debug'  pod 'Flipper-PeerTalk', versions['Flipper-PeerTalk'], :configuration => 'Debug'  pod 'Flipper-RSocket', versions['Flipper-RSocket'], :configuration => 'Debug'  pod 'FlipperKit/Core', versions['Flipper'], :configuration => 'Debug'  pod 'FlipperKit/CppBridge', versions['Flipper'], :configuration => 'Debug'  pod 'FlipperKit/FBCxxFollyDynamicConvert', versions['Flipper'], :configuration => 'Debug'  pod 'FlipperKit/FBDefines', versions['Flipper'], :configuration => 'Debug'  pod 'FlipperKit/FKPortForwarding', versions['Flipper'], :configuration => 'Debug'  pod 'FlipperKit/FlipperKitHighlightOverlay', versions['Flipper'], :configuration => 'Debug'  pod 'FlipperKit/FlipperKitLayoutTextSearchable', versions['Flipper'], :configuration => 'Debug'  pod 'FlipperKit/FlipperKitNetworkPlugin', versions['Flipper'], :configuration => 'Debug'end# Post Install processing for Flipperdef flipper_post_install(installer)  installer.pods_project.targets.each do |target|    if target.name == 'YogaKit'      target.build_configurations.each do |config|        config.build_settings['SWIFT_VERSION'] = '4.1'      end    end  endendtarget 'Fetcher' do  # Pods for Fetcher  pod 'Firebase/Analytics'  pod 'Firebase/Storage'  pod 'Firebase/Firestore'  pod 'Firebase/Auth'  pod 'Firebase/Database'  pod 'FBLazyVector', :path => "../node_modules/react-native/Libraries/FBLazyVector"  pod 'FBReactNativeSpec', :path => "../node_modules/react-native/Libraries/FBReactNativeSpec"  pod 'RCTRequired', :path => "../node_modules/react-native/Libraries/RCTRequired"  pod 'RCTTypeSafety', :path => "../node_modules/react-native/Libraries/TypeSafety"  pod 'React', :path => '../node_modules/react-native/'  pod 'React-Core', :path => '../node_modules/react-native/'  pod 'React-CoreModules', :path => '../node_modules/react-native/React/CoreModules'  pod 'React-Core/DevSupport', :path => '../node_modules/react-native/'  pod 'React-RCTActionSheet', :path => '../node_modules/react-native/Libraries/ActionSheetIOS'  pod 'React-RCTAnimation', :path => '../node_modules/react-native/Libraries/NativeAnimation'  pod 'React-RCTBlob', :path => '../node_modules/react-native/Libraries/Blob'  pod 'React-RCTImage', :path => '../node_modules/react-native/Libraries/Image'  pod 'React-RCTLinking', :path => '../node_modules/react-native/Libraries/LinkingIOS'  pod 'React-RCTNetwork', :path => '../node_modules/react-native/Libraries/Network'  pod 'React-RCTSettings', :path => '../node_modules/react-native/Libraries/Settings'  pod 'React-RCTText', :path => '../node_modules/react-native/Libraries/Text'  pod 'React-RCTVibration', :path => '../node_modules/react-native/Libraries/Vibration'  pod 'React-Core/RCTWebSocket', :path => '../node_modules/react-native/'  pod 'React-cxxreact', :path => '../node_modules/react-native/ReactCommon/cxxreact'  pod 'React-jsi', :path => '../node_modules/react-native/ReactCommon/jsi'  pod 'React-jsiexecutor', :path => '../node_modules/react-native/ReactCommon/jsiexecutor'  pod 'React-jsinspector', :path => '../node_modules/react-native/ReactCommon/jsinspector'  pod 'ReactCommon/callinvoker', :path => "../node_modules/react-native/ReactCommon"  pod 'ReactCommon/turbomodule/core', :path => "../node_modules/react-native/ReactCommon"  pod 'Yoga', :path => '../node_modules/react-native/ReactCommon/yoga', :modular_headers => true  pod 'DoubleConversion', :podspec => '../node_modules/react-native/third-party-podspecs/DoubleConversion.podspec'  pod 'glog', :podspec => '../node_modules/react-native/third-party-podspecs/glog.podspec'  pod 'Folly', :podspec => '../node_modules/react-native/third-party-podspecs/Folly.podspec'  pod 'react-native-maps', :path => '../node_modules/react-native-maps'  pod 'RNFBApp', :path => '../node_modules/@react-native-firebase/app'  pod 'tipsi-stripe', :path => '../node_modules/tipsi-stripe'  pod 'react-native-safe-area-context', :path => '../node_modules/react-native-safe-area-context'  pod 'RNReanimated', :path => '../node_modules/react-native-reanimated'  pod 'RNCMaskedView', :path => '../node_modules/@react-native-community/masked-view'  pod 'RNFBFirestore', :path => '../node_modules/@react-native-firebase/firestore'  pod 'RNFBAuth', :path => '../node_modules/@react-native-firebase/auth'  pod 'RNFBAnalytics', :path => '../node_modules/@react-native-firebase/analytics'  pod 'RNFBStorage', :path => '../node_modules/@react-native-firebase/storage'  pod 'react-native-image-picker', :path => '../node_modules/react-native-image-picker'  pod 'react-native-image-resizer', :path => '../node_modules/react-native-image-resizer'  pod 'RNFS', :path => '../node_modules/react-native-fs'  pod 'RNCPicker', :path => '../node_modules/@react-native-community/picker'  pod 'react-native-netinfo', :path => '../node_modules/@react-native-community/netinfo'  pod 'RNCPushNotificationIOS', :path => '../node_modules/@react-native-community/push-notification-ios'  pod 'RNVectorIcons', :path => '../node_modules/react-native-vector-icons'  target 'FetcherTests' do    inherit! :complete    # Pods for testing  end  use_native_modules!  # post_install do |pi|  #   pi.pods_project.targets.each do |t|  #     t.build_configurations.each do |config|  #       config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '9.0'  #     end  #   end  # end  # Enables Flipper.  #  # Note that if you have use_frameworks! enabled, Flipper will not work and  # you should disable these next few lines.  add_flipper_pods!  post_install do |installer|    installer.pods_project.targets.each do |t|      t.build_configurations.each do |config|        config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '9.0'      end    end    flipper_post_install(installer)  endendtarget 'Fetcher-tvOS' do  # Pods for Fetcher-tvOS  target 'Fetcher-tvOSTests' do    inherit! :search_paths    # Pods for testing  endend

And my other main Firebase project is initialized in AppDelegate.m and functions properly whenever I fetch something from the database or use auth.NOTE: I am not using auth on the second app, only firestore.


Viewing all articles
Browse latest Browse all 16750

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>