invertase / react-native-firebase

šŸ”„ A well-tested feature-rich modular Firebase implementation for React Native. Supports both iOS & Android platforms for all Firebase services.
https://rnfirebase.io
Other
11.64k stars 2.21k forks source link

šŸ”„ Exception 'Can't modify config objects after they are in use for FIRDatabaseReferences. #2888

Closed dakkafex closed 4 years ago

dakkafex commented 4 years ago

Issue

Trying to run my app on Ios but it crashes at the point it starts using the methods that work with the RNFBdatabse, which get called multiple times.

setLocation: function(geoLocation) : void {
    let uid = auth().currentUser.uid;
    let grid = Geohash.encode(geoLocation.latitude, geoLocation.longitude, 7);
    let dbRef = database().ref(`locationsX/${grid}/${uid}`);

    dbRef.set({
      geo: new firestore.GeoPoint(geoLocation.latitude, geoLocation.longitude),
      time: Date.now(),
    })
    .catch(e => console.log(e))
  },
  createMatches: function(geoLocation) : void {
    let uid: string = auth().currentUser.uid;
    let grid: string = Geohash.encode(geoLocation.latitude, geoLocation.longitude, 7);
    let neighbours = {...Geohash.neighbours(grid), c: grid};
    let locations = [];

    for (const n in neighbours) {
      database().ref(`locationsX/${neighbours[n]}`)
      .once('value')
      .then(docs => {
        docs.forEach((doc) =>{
          if (doc.key !== uid) {
            try {
              locations.push({
                latitude: doc.val().geo._latitude,
                  longitude: doc.val().geo._longitude,
                  time: doc.val().time,
                  profile: doc.key
              })
            }
            catch (error) {
              console.log(error);
            }
          }
        })
      })
      .then(() => {
        locations.forEach(loc => {
          let distanceBewteen = Tdistance([loc.latitude, loc.longitude], [geoLocation.latitude, geoLocation.longitude]);
          let lessThenMin = moment().diff(loc.time, 'm')
          if (distanceBewteen <= 0.2 && lessThenMin <= 5) {
            firestore()
              .collection(`users/${uid}/match`)
              .doc(loc.profile)
              .set({
                ID: loc.profile,
                L: new firestore.GeoPoint(loc.latitude, loc.longitude),
                T: firestore.Timestamp.fromMillis(loc.time),
              })
          }
        })
      })
    };
  }

Project Files

iOS

Click To Expand

#### `ios/Podfile`: - [ ] I'm not using Pods - [x] I'm using Pods and my Podfile looks like: ```ruby platform :ios, '9.0' require_relative '../node_modules/@react-native-community/cli-platform-ios/native_modules' target 'WhosThatApp' do # Pods for WhosThatApp 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/jscallinvoker', :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' 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 'RNVectorIcons', :path => '../node_modules/react-native-vector-icons' target 'WhosThatAppTests' do inherit! :search_paths # Pods for testing end use_native_modules! end target 'WhosThatApp-tvOS' do # Pods for WhosThatApp-tvOS target 'WhosThatApp-tvOSTests' do inherit! :search_paths # Pods for testing end end ``` #### `AppDelegate.m`: ```objc /** * Copyright (c) Facebook, Inc. and its affiliates. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */ @import Firebase; #import "AppDelegate.h" #import #import #import @implementation AppDelegate - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { RCTBridge *bridge = [[RCTBridge alloc] initWithDelegate:self launchOptions:launchOptions]; RCTRootView *rootView = [[RCTRootView alloc] initWithBridge:bridge moduleName:@"WhosThatApp" initialProperties:nil]; if ([FIRApp defaultApp] == nil) { [FIRApp configure]; } rootView.backgroundColor = [[UIColor alloc] initWithRed:1.0f green:1.0f blue:1.0f alpha:1]; self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds]; UIViewController *rootViewController = [UIViewController new]; rootViewController.view = rootView; self.window.rootViewController = rootViewController; [self.window makeKeyAndVisible]; return YES; } - (NSURL *)sourceURLForBridge:(RCTBridge *)bridge { #if DEBUG return [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index" fallbackResource:nil]; #else return [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"]; #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 10.15 CPU: (4) x64 Intel(R) Core(TM) i5-4670 CPU @ 3.40GHz Memory: 628.63 MB / 8.00 GB Shell: 3.2.57 - /bin/bash Binaries: Node: 10.16.3 - /usr/local/bin/node Yarn: 1.19.1 - /usr/local/bin/yarn npm: 6.11.3 - /usr/local/bin/npm Watchman: 4.9.0 - /usr/local/bin/watchman SDKs: iOS SDK: Platforms: iOS 13.1, DriverKit 19.0, macOS 10.15, tvOS 13.0, watchOS 6.0 IDEs: Xcode: 11.1/11A1027 - /usr/bin/xcodebuild npmPackages: react: 16.9.0 => 16.9.0 react-native: 0.61.3 => 0.61.3 npmGlobalPackages: react-native-cli: 2.0.1 ``` - **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:** - `6.0.3` - **`Firebase` module(s) you're using that has the issue:** - `Realtime database` - **Are you using `TypeScript`?** - `Y` & `3.6` **_note: i am only using it in this file to create helper functions_**


Think react-native-firebase is great? Please consider supporting all of the project maintainers and contributors by donating via our Open Collective where all contributors can submit expenses. [Learn More]

ghsdh3409 commented 4 years ago

Same here!

stale[bot] commented 4 years ago

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 the community's attention?

This issue will be closed in 15 days if no further activity occurs. Thank you for your contributions.

stale[bot] commented 4 years ago

Closing this issue after a prolonged period of inactivity. If this is still present in the latest release, please feel free to create a new issue with up-to-date information.

cmcleese commented 4 years ago

This is still happening

zhigang1992 commented 4 years ago

Duplicates of https://github.com/invertase/react-native-firebase/issues/2838