Firebase listener when app is in the background

后端 未结 4 2066
逝去的感伤
逝去的感伤 2020-12-05 21:52

I have a Firebase childAdded event listener for the notifications table in my app that I would like to trigger push notifications when the app is in the backgro

4条回答
  •  北海茫月
    2020-12-05 22:49

    I had the same problem and came across your post months ago. I have managed to finally understand what is required to observe notifications in the background.

    I have detailed the solution that I am using in this post https://stackoverflow.com/a/42240984/7048719

    The technique is as follows

    1. use a custom data service class
    2. initialise a sharedInstance of the data service class
    3. call the appropriate function in the data service class sharedInstance from your initial view controller.

    This way the observer stays in memory

    Update: Apple have implemented updates in regards to background modes which have stopped this method from working.

提交回复
热议问题