hva*_*sam 6 ios firebase swift firebase-realtime-database
背景:
我有一个应用程序,新用户填写注册表单(包括用户名,电子邮件和密码)注册帐户.当新用户提交表单时,应用会检查其Firebase数据库以查看是否已使用该用户名.这里的问题observeSingleEvent(of:with:)是没有得到最新的数据.当我直接从Firebase控制台更新数据时,更改不会反映在返回的结果中observeSingleEvent(of:with:).即使在应用程序重新启动之间,也不会返回新的数据更改.
我在这个问题上唯一看到的就是这里.用户说使用时没有启用持久性observeSingleEvent(of:with:).但是,我有持久性禁用.另外,我设置keepSynced()的FIRDatabase实例为假(和我试过也是如此).两种设置都没有运气.
这是我正在尝试的一个例子:
let usersDatabaseReference = FIRDatabase.database().reference().child("users")
usersDatabaseReference.keepSynced(false)
// Query the database to see if the username is available
// The user with the username "mark" was removed from the database via the Firebase console
let username = "mark" // This user used to exist in the database (and was previously added through the app).
usersDatabaseReference.child(username).observeSingleEvent(of: .value, with: { (snapshot) in ... } )
Run Code Online (Sandbox Code Playgroud)
上面的代码块应该返回最新的数据(用户"mark"不应该存在的数据).
我想知道是否有其他人遇到这个问题,或者是否有人有可能的解决方案.
注意:使用iOS 10.1和swift 3进行开发.
所以,我的问题与缓存或获取旧结果无关。我的一些代码逻辑依赖于检查在 的完成处理程序中传回的value参数。我错误地认为我可以通过与;进行比较来检查数据库值。这导致了对结果的误解。snapshotobserveSingleEvent(of:with:)nullnil
实际检查数据库获取的最佳方法null是调用实例exists()上的方法FIRDataSnapshot。如果包含非值则exists()返回。truesnapshotnull
| 归档时间: |
|
| 查看次数: |
583 次 |
| 最近记录: |