简体   繁体   中英

Firebase Works In Simulator But Not On iPhone

I am trying to pull in data on a certain View Controller from my Firebase database using the following:

_refHandle = [_postRef observeEventType:FIRDataEventTypeValue withBlock:^(FIRDataSnapshot * _Nonnull snapshot) {
  NSDictionary *postDict = snapshot.value;
  // ...
}];

The code works great in the simulator but not working on the iPhone(code gets skipped over). I use this piece of code in other parts of my application and it works on both the device and simulator. I have also implemented this piece of code into a custom method for pulling in data (Still does not work). Does anyone know why this is not working on a real device?

I found that if you logged in, and delete the application, then after you install the application again, you will still be logged in. I do not know exactly, but I assumed that Firebase somehow binds the account cache to the Keychain with Bundle Identifier, not in the app local storage.

My solution is not good enough but it worked for me:

  1. Remove your APP from real device.
  2. Go to your project in Navigation Panel.
  3. In General tab change your Bundle identifier, for example: "myApp.com" to "myApplication.com" or whatever you want.
  4. Build and run
  5. Bingo!

Update: Firebase remembers your data in keychain using your Bundle identifier as key, that's why it works when you change Bundle Identifier

It happens because of your security rules. In your Firebase Console:

  • Go to the Database menu item
  • Go to the Rules tab
  • Update the security rule to:

     { "rules": { ".read": true, // Or whatever rule you would like ".write": "auth != null" } }

Go to the Database menu item

Go to the Rules tab

Update the security rule to (for real device):

{
 "rules": 
    {
     ".read": "auth != null",
     ".write": "auth != null"
     }
}

Update the security rule to (for real simulator Test):

 {
   "rules": 
    {
     ".read": "auth == null",
     ".write": "auth == null"
     }
 }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM