简体   繁体   中英

IOS Firestore Offline Access

In my app and AppDelegate I have:

import UIKit
import Capacitor
import Firebase
import FirebaseCore
import FirebaseDatabase
import FacebookCore

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

    var window: UIWindow?

    
    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
        FirebaseApp.configure()
        Database.database().isPersistenceEnabled = true
        ApplicationDelegate.shared.application(
         application,
         didFinishLaunchingWithOptions: launchOptions
        )
        return true
    }

在此处输入图像描述

I am using Capacitor for the App as well.

In my query, I use something simple like:

const useItemsUser = () => {
  const user = firebase.auth().currentUser;
  const user1 = user.uid;
  const [items, setItems] = useState([]);
  useEffect(() => {
    const unsubscribe = firebase
      .firestore()
      .collection("user")
      .where("id", "==", `${user1}`)
      .onSnapshot(snapshot => {
        const listItemsUsers = snapshot.docs.map(doc => ({
          id: doc.id,
          ...doc.data()
        }));
        setItems(listItemsUsers);
      });
    return () => unsubscribe();
  }, []);
  return items;
};

But yet if I am offline a blank response comes back with the error of:

@firebase/firestore: Firestore (8.10.1): Connection WebChannel transport errored

I am assuming my AppDelegate is correct and it has something to do with the onSnapshot? Is anyone able to assist?

As the workaround mentioned in this github try to use experimentalForceLongPolling in your Firestore settings.

firebase.initializeApp(firebaseConfig);
firebase.firestore().settings({ experimentalForceLongPolling: true });

Also check the below links for similar implementations:

I have found this github thread raised for a similar issue which is still open.If you are still facing the issue, you can follow that issue for future updates and also add your concerns there.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM