[英]Firebase connecting with simulator but not in real device iOS
I am developing a app which has the connection with Firebase DB. 我正在开发与Firebase DB有连接的应用程序。 This is one part of my code, 这是我代码的一部分,
let ref1 = Database.database().reference()
ref1.child("UserId").child("\(user_id)").setValue(["name": "\(name)"])
And this one is working fine in simulator(updating value in firebase DB), but not in real device. 而且这一程序在模拟器中工作正常(在Firebase DB中更新值),但在实际设备中却没有。 I have tried some solutions from this site, still I can't get the output. 我已经从该站点尝试了一些解决方案,但仍然无法获得输出。
Is anyone there to help me? 有谁可以帮助我吗?
This could be because you are not authenticated on your device or any other reasons. 这可能是因为您未在设备上进行身份验证或任何其他原因。 In order to debug it, I suggest you to add a completion block for your setValue
which is going to be called whenever the write has been committed to the database. 为了对其进行调试,建议您为setValue
添加一个完成块,只要将写入提交到数据库,就会调用该完成块。 If the call was unsuccessful for any reasons, you can get the error object and take a look at the error. 如果由于某种原因调用失败,则可以获取错误对象并查看错误。
yourRef.setValue(["name": "\(name)"]) { (error, dbRef) in
if (error != nil) {
//catch the error here
print("Data could not be saved.")
} else {
print("Data saved successfully!")
}
}
At last, the issue was the real device's date and time. 最后,问题是真实设备的日期和时间。 The date and time was incorrect in my device. 我的设备中的日期和时间不正确。 So, the connection with firebase DB failed. 因此,与Firebase DB的连接失败。 Now, it's fixed. 现在,它已修复。 Thanks for you suggestions!! 谢谢你的建议!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.