Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/410.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Firestore离线似乎不起作用_Javascript_Firebase_React Native_Google Cloud Firestore - Fatal编程技术网

Javascript Firestore离线似乎不起作用

Javascript Firestore离线似乎不起作用,javascript,firebase,react-native,google-cloud-firestore,Javascript,Firebase,React Native,Google Cloud Firestore,我是react native和rnfirebase.io以连接到firestore 我的环境如下: Environment: OS: macOS High Sierra 10.13.1 Node: 8.9.2 Yarn: 1.5.1 npm: 5.8.0 Watchman: 4.9.0 Xcode: Xcode 9.1 Build version 9B55 Android Studio: 3.1 AI-173.4720617 Packages: (wanted =&

我是react native和rnfirebase.io以连接到firestore 我的环境如下:

Environment:
  OS: macOS High Sierra 10.13.1
  Node: 8.9.2
  Yarn: 1.5.1
  npm: 5.8.0
  Watchman: 4.9.0
  Xcode: Xcode 9.1 Build version 9B55
  Android Studio: 3.1 AI-173.4720617

Packages: (wanted => installed)
  react: 16.3.1 => 16.3.1
  react-native: 0.55.2 => 0.55.2
我希望我的应用程序脱机工作,我在上看到Firestore默认支持脱机

下面是我向Firestore添加行的代码

const db = firebase.firestore().collection('bill');

const data = {
  userid: firebase.auth().currentUser.uid,
  year: year,
  month: month,
  description: description,
  dateCreated: new Date()
};

db.add(data).then(ref => {
   console.log('Added bill with ID: ', ref.id);
}).catch(error => {
   console.error("Error adding bill: ", error);     
}); 
当有互联网连接时,一切都会顺利进行。当我关闭互联网连接并试图添加一条记录时,这就像要花很长时间才能添加一样

我匿名验证我的用户,如下所示

  componentWillMount() {

    const user = firebase.auth().currentUser;

    if (!user) {

      firebase.auth()
        .signInAnonymouslyAndRetrieveData()
        .then(credential => {
          if (credential) {
            console.log('default app user ->', credential.user.toJSON());
          } else {
            console.log('failed to auth anonymous user');
          }
      });

    }    

  }