swift-无法识别.childchanged上的Firebase观察者 [英] Swift - Firebase observer on .childchanged is not being recognized
本文介绍了swift-无法识别.childchanged上的Firebase观察者的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是下面的代码,即使我通过应用程序或直接在Firebase中更改名为"tokens"的子节点,也将无法执行!
Here is the code below, it will not get executed even if I change the child node called "tokens" in the Firebase via app or directly in Firebase!?
handle = ref.child("Users").child(uid).child("tokens").observe(.childChanged, with: { snap in
print("Changed Token Count: ", snap.value!)
if snap.value is NSNull {
// Child not found
} else {
if (currTokenCount < snap.value as! UInt) {
print("Value increased....")
} else {
print("Value decreased....")
}
}
}) { (error) in
print(error.localizedDescription)
}
推荐答案
我假设您具有这样的数据结构:
I assume you have a data structure like this:
Users
uid1
tokens: "value of tokens"
如果要在上述结构中侦听特定用户对令牌的更改,请使用 .value
侦听器:
If you want to listen for changes to token
of a specific user in the above structure, use a .value
listener:
handle = ref.child("Users").child(uid).child("tokens").observe(.value, with: { snap in
print("Changed Token Count: ", snap.value!)
if snap.value is NSNull {
// Child not found
} else {
if (currTokenCount < snap.value as! UInt) {
print("Value increased....")
} else {
print("Value decreased....")
}
}
}) { (error) in
print(error.localizedDescription)
}
.child * 侦听器仅在您的子节点位于
令牌下时使用,例如:
The .child*listeners are only used when you have child nodes under
tokens`, like:
Users
uid1
tokens
token1: "value of token1"
token2: "value of token2"
这篇关于swift-无法识别.childchanged上的Firebase观察者的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文