gpt4 book ai didi

ios - 如果用户与互联网断开连接,Firebase 会更新 Firebase 上的值

转载 作者:行者123 更新时间:2023-11-30 12:30:13 25 4
gpt4 key购买 nike

如何在设备断开连接之前写入 Firebase,如果用户与互联网断开连接,我会尝试更新 Firebase 上的值。我不确定是否有方法可以做到这一点。我搜索并找到了 onDisconnect 但这仅在用户注销时有帮助。如果有任何建议,我们将不胜感激。

func isUserLoggedInSaved(){
if let user = FIRAuth.auth()?.currentUser {
if !user.isAnonymous {

let path = "rquest/frontEnd/users/\(self.currentUserId()!)"
let connectedRef = FIRDatabase.database().reference(withPath: ".info/connected")

let presenceRef = FIRDatabase.database().reference(withPath: path).child("isUserLogon")
presenceRef.onDisconnectSetValue(false, withCompletionBlock: { (err, fir) in
print("Disconnected")
})
connectedRef.observe(.value, with: { snapshot in
if let connected = snapshot.value as? Bool, connected {
self.childRef(path).updateChildValues(["isUserLogon":true])
print("connectedssss")
return
}else{
print("not connected anymore ")
if #available(iOS 10.0, *) {
Timer.scheduledTimer(withTimeInterval: 3, repeats: false, block: { (timer) in
self.navAlertCustom(viewType: .StatusLine, theme: Theme.warning, duration: 10, location: .top, message: "No Internet Connection", dimBg: false)
})

})
} else {
// Fallback on earlier versions
}
}
})
}
}
}

最佳答案

查看文档

FIRDatabase.database().reference().onDisconnectSetValue(value: Any)

cmd+clickonDisconnectSetValue 上,您将导航到文档:-

Ensure the data at this location is set to the specified value when the client is disconnected (due to closing the browser, navigating to a new page, or network issues)...

关于ios - 如果用户与互联网断开连接,Firebase 会更新 Firebase 上的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43647575/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com