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?