Firebase 3x方法不能在真实的设备上工作,但在模拟器Swift 3.0上工作 [英] Firebase 3x method not working in real device but working on simulator Swift 3.0

查看:127
本文介绍了Firebase 3x方法不能在真实的设备上工作,但在模拟器Swift 3.0上工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在使用Google Firebase 3.x版本,并且遇到了来自Firebase的奇怪问题。我们正在使用Swift 3.0和获取用户的详细信息,我们正在使用以下代码片段:


$ b $ pre $ func getUserDetails(uid text:String !,userBlock:@escaping(_ details:AnyObject) - > Void){
//检查DB引用是否为零。
if self.rootDBRef == nil {
self.rootDBRef = FIRDatabase.database()。reference()
}
//检查输入文字不能为空
如果text.trim()。characters.count == 0 {
userBlock(as AnyObject)
return
}
let query = self.rootDBRef.child(用户)。queryOrdered(byChild:uid)。queryEqual(toValue:text)
query.observeSingleEvent(of:.value,with:{(dbSnapshot)in
guard let snap:FIRDataSnapshot?= dbSnapshot else {
print(No Result Found)
return
}
如果snap?.value是NSNull {
// block(found:false)
userBlock(as AnyObject)
return
}
让dict = snap?.value as![String:AnyObject]
userBlock(作为AnyObject的字典)
$)

这个代码永远不会被真正的设备调用,我们也没有得到任何错误日志,但是同样的代码在模拟器中工作。它是一个奇怪的问题,是的,我已经检查了一个类似的问题: Firebase没有工作在真实设备上(iOS)



我也尝试禁用BitCode,但是根本不起作用。 b
$ b

我们在Xcode 8中使用了iOS 9设备。任何帮助都是值得赞赏的。

解决方案

我认为问题出在身份验证上。您必须在 Firebase 启用身份验证,但是没有身份验证用户。因此,您不能访问 Firebase strong>。


We are working with Google Firebase 3.x version and we faced strange issue from Firebase. We are using Swift 3.0 and for getting user details, we are using the following code snippet:

 func getUserDetails(uid text:String!, userBlock:@escaping (_ details:AnyObject) -> Void) {
        //check DB Reference is nil or not.
        if self.rootDBRef == nil {
            self.rootDBRef = FIRDatabase.database().reference()
        }
        //check input text must not be empty
        if text.trim().characters.count == 0 {
            userBlock("" as AnyObject)
            return
        }
        let query = self.rootDBRef.child("users").queryOrdered(byChild: "uid").queryEqual(toValue: text)
        query.observeSingleEvent(of: .value, with: { (dbSnapshot) in
            guard let snap: FIRDataSnapshot? = dbSnapshot else {
                print("No Result Found")
                return
            }
            if snap?.value is NSNull {
                //block(found: false)
                userBlock("" as AnyObject)
                return
            }
            let dict = snap?.value as! [String : AnyObject]
            userBlock(dict as AnyObject)
        })
    }

That code never gets called in a real device and we're not getting any error logs, but that same code works in a simulator. Its a strange issue and yes, I have already checked a similar question: Firebase not worked on real devices (iOS)

I've also tried to disable BitCode as well, but that didn't work at all.

We are using iOS 9 device with Xcode 8. Any help is appreciated.

解决方案

I think the problem is on Authentication. You must have Enable Authentication on Firebase but has not Authenticate user.So you are not allowed to access the database on Firebase.

这篇关于Firebase 3x方法不能在真实的设备上工作,但在模拟器Swift 3.0上工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆