Firebase 3x method not working in real device but

2019-02-22 13:14发布

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.

2条回答
在下西门庆
2楼-- · 2019-02-22 13:57

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.

查看更多
够拽才男人
3楼-- · 2019-02-22 14:05

You have to enable Anonymous login in FireBase

Anonymous Login

And according to FireBase Documentation

You have to add FIRAuth.auth()?.signInAnonymously() in your didFinishLaunchingWithOptions in the AppDelegate to enable Anonymous Login

查看更多
登录 后发表回答