【发布时间】:2020-04-16 13:23:46
【问题描述】:
当前用户观看视频广告后,将检索他们的分数(存储在 Firebase 中)并将他们的分数加 1。然后,它将更新文档并显示用户拥有的点数。好像一切都还好,除了,我做不到scoreText.text = point
func rewardBasedVideoAd(_ rewardBasedVideoAd: GADRewardBasedVideoAd, didRewardUserWith reward: GADAdReward) {
let dBRef = Database.database().reference()
dBRef.child("Users").child(Auth.auth().currentUser!.uid).queryOrderedByKey().observeSingleEvent(of: .value, with: { snapshot in
guard let dict = snapshot.value as? [String:Any] else {
print("Error")
return
}
var point = dict["point"] as? Int
point!+=1
dBRef.child("users").child(Auth.auth().currentUser!.uid).setValue(["point": point])
scoreText.text = point
})
如何显示用户的积分?
[更新代码] 更改代码以访问 Cloud Firestore,而不是实时数据库
func rewardBasedVideoAd(_ rewardBasedVideoAd: GADRewardBasedVideoAd, didRewardUserWith reward: GADAdReward) {
//[START update_document-increment
let docRef = db.collection("users").document(UserID!)
// Atomically increment the population of the city by 1.
docRef.updateData([
"points": FieldValue.increment(Int64(1))
])
//[END update_document-increment]
//insert point value here
scoreText.text =
【问题讨论】:
-
我不清楚你的问题是什么。您可以编辑您的问题以包含minimal, complete/standalone reproduction of the problem you're asking about。我强烈建议研究该链接,因为遵循其中的建议会增加有人提供帮助的机会。
-
感谢您的评论!我希望我已经把它说得更具体了。
标签: firebase firebase-realtime-database google-cloud-firestore swift5