0

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
    }

enter image description here

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?

Paul VI
  • 515
  • 1
  • 8
  • 25

1 Answers1

0

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.

Sathi Aiswarya
  • 2,068
  • 2
  • 11