应用程序处于后台 iOS 时的 Firebase 数据库事务 [英] Firebase database transaction when app is in background iOS
问题描述
我正在处理交互式推送通知,当我回复 PN 时,它应该更新 firbase 数据库.它不能很好地工作,因为有时如果应用程序在后台,数据不会实时同步.但是当你打开应用程序时,它会推送数据
I am working with interactive push notifications, when i reply to a PN, which should be updating firbase databsae. It doesn't works well because some times if the app is in background the data is not synced in real time. but when u open the app it pushes the data
如果应用处于终止状态,则回复甚至不会发送到 Firebase DB
if the app is in a killed state the reply is not even send to Firebase DB
Ref.child(uId).runTransactionBlock({ (currentData: FIRMutableData) -> FIRTransactionResult in
var value = currentData.value as? [String : AnyObject]
if value == nil {
return FIRTransactionResult.success(withValue: currentData)
}
let totR = value!["totalReply"] as? Int ?? 0
print(totR)
value?["totalReply"] = totR + 1
currentData.value = value
}
推荐答案
Firebase 数据库不提供后台同步.相反,它会在应用程序运行时实时同步数据.对于后台同步,您可以使用 Firebase Cloud Messaging 唤醒应用,以便数据库可以同步其数据.
Firebase Database does not provide background syncing. Instead, it syncs data in realtime while the app is actively running. For background syncing you could use Firebase Cloud Messaging to wake the app up so that Database can then synchronize its data.
这篇关于应用程序处于后台 iOS 时的 Firebase 数据库事务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!