iOS App crashed com.apple.root.background-qos

寵の児 提交于 2019-12-08 02:58:26

I assumed that the data app crashes happen because of the incorrect functions in the runtime. After changing the function, I no longer have app crashes.

private var queuesKey = 0
private var referencesKey = 1

extension UIViewController {

    var firQueues: [DatabaseQuery]? {
        get {
            return objc_getAssociatedObject(self, &queuesKey) as? [DatabaseQuery]
        }
        set {
            objc_setAssociatedObject(self, &queuesKey, newValue, objc_AssociationPolicy.OBJC_ASSOCIATION_RETAIN)
        }
    }

    var firReferences: [DatabaseReference]? {
        get {
            return objc_getAssociatedObject(self, &referencesKey) as? [DatabaseReference]
        }
        set {
            objc_setAssociatedObject(self, &referencesKey, newValue, objc_AssociationPolicy.OBJC_ASSOCIATION_RETAIN)
        }
    }


    func removeFIRQueuesReferensesObservers() {
        if var _firQueues = firQueues {
            for firQueqry in _firQueues {
                firQueqry.removeAllObservers()
            }
//            debugPrint("removeFIRQueuesReferensesObservers _firQueues start", _firQueues.count, "firQueues", firQueues?.count ?? "nil")
            _firQueues.removeAll()
            firQueues?.removeAll()
//            debugPrint("removeFIRQueuesReferensesObservers _firQueues end", _firQueues.count, "firQueues", firQueues?.count ?? "nil")
        }

        if var _firReferences = firReferences {
            for firRef in _firReferences {
                firRef.removeAllObservers()
            }
//            debugPrint("removeFIRQueuesReferensesObservers _firReferences start", "_firReferences", _firReferences.count, "firReferences", firReferences?.count ?? "nil")
            _firReferences.removeAll()
            firReferences?.removeAll()
//            debugPrint("removeFIRQueuesReferensesObservers _firReferences end", "_firReferences", _firReferences.count, "firReferences", firReferences?.count ?? "nil")
        }
    }

}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!