【问题标题】:Firebase database transaction when app is in background iOS应用程序在后台 iOS 时的 Firebase 数据库事务
【发布时间】:2016-08-18 06:21:39
【问题描述】:

当我回复一个 PN 时,我正在处理交互式推送通知,这应该是更新 firbase 数据库。它不能很好地工作,因为有时如果应用程序在后台,数据不会实时同步。但是当你打开应用程序时,它会推送数据

如果应用处于终止状态,则回复甚至不会发送到 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
}

【问题讨论】:

    标签: ios swift firebase firebase-realtime-database firebase-notifications


    【解决方案1】:

    Firebase 数据库不提供后台同步。相反,它会在应用程序正在运行时实时同步数据。对于后台同步,您可以使用 Firebase Cloud Messaging 唤醒应用,以便数据库可以同步其数据。

    【讨论】:

    • 那很不方便,如果应用程序被杀死,Firebase 数据库事务甚至不会存储数据,如果它在后台它会在应用程序打开时拾取并同步数据,而不是在那之前跨度>
    猜你喜欢
    • 2017-05-08
    • 2019-09-08
    • 1970-01-01
    • 1970-01-01
    • 2018-07-10
    • 1970-01-01
    • 2011-07-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多