Firebase FEventTypeChildAdded callback gets called multiple times for the same new object

前端 未结 1 1042
野性不改
野性不改 2021-01-28 17:23

I am working on an iOS app and I have built my project on top of Firebase\'s login-demo app. I can authenticate with Facebook, and communicate with Firebase just fine. When I pr

相关标签:
1条回答
  • 2021-01-28 18:17

    I've never used the Firebase iOS SDK, but it most likely works in a similar way to the other SDKs.

    If that is the case, the listener block that you registered, stays registered when the user logs out. Then when the user logs in again, you are registering a second event listener. So from that moment on, your code block will execute twice for every added child.

    You should unregister/cancel the event listeners when the user logs out (https://www.firebase.com/docs/ios/api/#firebase_removeAllObservers) or simply not re-register them again if you've already registered them before.

    See the Firebase guide for iOS, specifically the section on detaching blocks: https://www.firebase.com/docs/ios/guide/retrieving-data.html#section-detaching

    0 讨论(0)
提交回复
热议问题