RxSwiftCommunity / RxFirebase

RxSwift extensions for Firebase
MIT License
224 stars 66 forks source link

RxSwift Firestore extension is not working #24

Closed Jigneshmayani90 closed 5 years ago

Jigneshmayani90 commented 5 years ago

Here is my Original code that is working i am getting data from firestore

    db.collection(UserNode).document("affdToWcXulhFtlFdcqm").collection(MessageNode).whereField("isDelete", isEqualTo:false)
        .addSnapshotListener
        { querySnapshot, error in

            guard let snapshot = querySnapshot else
            {
                return
            }

            snapshot.documentChanges.forEach { diff in

                if (diff.type == .added)
                {
               // Here I am getting Data
                }
                if (diff.type == .modified)
                {
                    print("Modified : \(diff.document.data())")
                }
                if (diff.type == .removed)
                {
                    print("Removed : \(diff.document.data())")
                }
            }
    }

Same Thing i want to do with Rxfirebase with this code

    db.collection(UserNode).document("affdToWcXulhFtlFdcqm").collection(MessageNode).whereField("isDelete", isEqualTo:false).rx.listen()
        .subscribe(onNext: { snapshot in
            snapshot.documentChanges.forEach { diff in
                if (diff.type == .added) {
                    print("Added: \(diff.document.data())")
                }
                if (diff.type == .modified) {
                    print("Modified: \(diff.document.data())")
                }
                if (diff.type == .removed) {
                    print("Removed: \(diff.document.data())")
                }
            }
        }, onError: { error in
            print("Error fetching snapshots: \(error)")
        }).disposed(by: disposeBag)

But in my case i am not getting Data event from firestore

But I am able to save data on firestore with Rxswift by using this method

    docRef.rx.updateData([stringKey:true]).subscribe(onNext:
    { _ in
        // Success
    }).disposed(by: disposeBag)

Please help me i am doing any mistake ? I can update data. but i am not able to retrieve data.

arnauddorgans commented 5 years ago

Hi, sorry i'm late

I did some tests with your code and i'm able to get data event from firestore.

Capture d’écran 2019-07-10 à 10 45 43 Capture d’écran 2019-07-10 à 10 41 35 Capture d’écran 2019-07-10 à 10 46 13

Can you add a .debug() just before your subscribe ? Maybe your subscription is disposed before getting any event for some reasons.

Jigneshmayani90 commented 5 years ago

Arnauddorgans i just removed disposed(by: disposeBag) and i am getting event you are right.

Thanks for your Help.