在iPhone而非iMac模拟器上运行时,是什么导致连续不断的Firebase命中?

问题描述

在iPhone的Mac模拟器上,它可以正常工作。在实际的iPhone上,即使您将该页面留在应用程序上,页面中的一个页面也会持续访问数据库。然后,这使应用程序不堪重负。如果您在控制台中查看它,则它是来自Firebase请求的连续运行数据流。其根本原因是,在iPhone上运行时会发生这种情况,而在Mac上的iPhone模拟器中运行时不会发生这种情况。 我知道很难理解零碎的代码,但是粘贴所有内容太长了。以下是导致问题的相关快照代码。是的,我知道有嵌套的快照,但是就像我在模拟器上提到的那样,它运行完美。

**let thisUsersUid = Auth.auth().currentUser?.uid //Mr. Dunn's uid

refArtists = Database.database().reference().child("people");

refArtists.observe(DataEventType.value,{snapshot in

…………
    
    self.refArtists.observeSingleEvent(of:.value,with: {snapshot in
        
        let myDomain = snapshot.value as? String
        self.bSnap = myDomain
        print("haaal",self.bSnap)

 ……….

        thisPersonRef.observeSingleEvent(of:.value,with: {snapshot in
        
        if snapshot.exists() {
        
        let query = Database.database().reference().child("people").queryOrdered(byChild: "e2").queryEqual(tovalue: self.bSnap)
        query.observeSingleEvent(of: .value,with: { snapshot in
        var allUsers = snapshot.children.allObjects as! [DataSnapshot]
        ///////end (1) of comment
        if let index = allUsers.firstIndex(where: { $0.key == myUid } ) {
        allUsers.remove(at: index) //remove the current user
        } /////end (2) of comment
        
        for usersnap in allUsers {
        let name = usersnap.childSnapshot(forPath: "postID").value as? String
        print(name,"NNN")
        
        if let unwrappedname = name {
        self.array1.append(unwrappedname)
        
        
        print(self.array1,"uuu")
        
        self.filteredArray = self.array1
        let thisUsersUid = Auth.auth().currentUser?.uid //Mr. Dunn's uid
        
        
        if snapshot.childrenCount>0{
        
        self.people.removeAll()
        
        for people in snapshot.children.allObjects as! [DataSnapshot] {
        
        
        if people.key != thisUsersUid {
        …….
        
        
        return Calendar.current.isDateInToday(date1)
        }
        
        print(filteredResults,"ppp")
        let countb = filteredResults.compactMap({$0}).count
        print(countb,"bbb")

        ……..
        
        if Calendar.current.isDateInToday(date) &&  countb >= 1  {
        
        ………..
        self.people.append(peopl)
        

        } else {
        print ("whr")
        }
        } else {
        print ("Alp")
        
        }
        }

        print(self.array1,"los")
        print(people.key,"posss")
        }
        
        self.people.sort(by: { $0.TodayLikeCount ?? 0 > $1.TodayLikeCount ?? 0 })
        
        self.table.reloadData()

        }

        }
        }

        })
        
        } else {
        print("no")
        
        }
        
        })

    })
 }
 **

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)