0
デバイスが切断される前にFirebaseに書き込む方法はありますか?ユーザーがインターネットから切断された場合、Firebaseの値を更新しようとしています。それを行う方法があるかどうかはわかりません。私は検索してonDisconnect
を見つけましたが、ユーザーがログアウトするときにのみ役立ちます。感謝する提案があればFirebaseは、ユーザーがインターネットから切断された場合にfirebaseの値を更新します。
FIRDatabase.database().reference().onDisconnectSetValue(value: Any)
cmdがonDisconnectSetValue
にをクリック+のドキュメントを見て
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
}
}
})
}
}
}