这是下面的代码,即使我通过应用程序或直接在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)
}
答案 0 :(得分:2)
我假设您具有这样的数据结构:
app.get('/activity/test', function(req,res) {
res.writeHead(200);
res.end("hello world\n");
console.log("Entered GET");
});
如果要在上述结构中侦听特定用户对Users
uid1
tokens: "value of tokens"
的更改,请使用token
侦听器:
.value
.child * 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)
}
令牌,例如:
listeners are only used when you have child nodes under