TableView not reloading with firebase data after dismissing modal controller

Viewed 73

After logging in with firebase Auth, I try to update the home page tableview using a delegate except I get this issue -

2020-07-16 10:58:51.078331-0700 Appname[44300:8867431] [AXRuntimeCommon] Unknown client: Appname
2020-07-16 10:58:51.084416-0700 Appname[44300:8867435] [AXRuntimeCommon] AX Lookup problem - errorCode:1100 error:Permission denied portName:'com.apple.iphone.axserver' PID:44186 

Once the app loads it checks if the user is logged in on the home page with this function

func isLoggedIn() {
        if Firebase.Auth.auth().currentUser == nil {
            perform(#selector(handleLogout), with: nil, afterDelay: 0)
        }
    }

    @objc func handleLogout() {
        
        do {
            try Auth.auth().signOut()
        } catch let logoutError {
            print("logout error", logoutError)
        }
        
        let startview = StartView()
        startview.home = self
        let nav = UINavigationController(rootViewController: startview)
        nav.modalPresentationStyle = .fullScreen
        present(nav, animated: false)
    }

Then in the login page it logs the user in and runs the function from the home page but it just shows up as blank.

@objc func Login() {
Auth.auth().signIn(withEmail: EmailField.text!, password: PasswordField.text!) { [weak self] (user, error) in
       
        guard let StrongSelf = self else {
            return
        }
        guard let result = user, error == nil else {
            print(error!._code)
            self?.handleError(error!)
            return
        }
        
        let user = result.user
        print("logged in \(user)")

         //NotificationCenter.default.post(name: NSNotification.Name(rawValue: "loadhome"), object: nil)
        StrongSelf.navigationController?.dismiss(animated: true, completion: {
            self?.home.loadfirstusers()
        })
    }
}
    var home = HomePage()

It calls this function to update the user data and gets as far as printing sameunisamecourse but it doesn't call the print inside the dispatch.notify for some reason?

func SameUniSameCourse(completion: @escaping (_ success: Bool) -> Void) {
        self.dispatchGroup.enter()
        service.loadUniversityAndCourse { (uni, course) in
        defer{ self.dispatchGroup.leave() }

            let usersRef = Firestore.firestore().collection("users").order(by: "Created", descending: true).whereField("University", isEqualTo: uni).whereField("Course", isEqualTo: course)
            self.dispatchGroup.enter()
            usersRef.getDocuments { (snapshot, error) in
            print("samecoursesameuni")
            defer{ self.dispatchGroup.leave() }
                
            if let error = error {
                print(error.localizedDescription)
                                    
            } else {
                for document in snapshot!.documents {
                    let data = document.data()
                    //print(data)
                    if let dictionary = data as [String:AnyObject]? {
                    let Info = UserInfo(dictionary: dictionary)
                    if Info.uid == Auth.auth().currentUser?.uid {
                        //print(Info.username)
                    }
                    else {
                    self.sameUniSameCourse.append(Info)
                        //print(Info.username!)
                }}}

                }
        }}
        self.dispatchGroup.notify(queue: .main) {
            print("dispatchNotifyCalled")
            if self.sameUniSameCourse.isEmpty == true {
                completion(false)
            }
            else {
                self.masterArray.append(contentsOf: self.sameUniSameCourse)
                self.spinner.stopAnimating()
                completion(true)
            }
      }
}

0 Answers
Related