6

I have an application developed in Flutter, and I have some problem with it on IOS when activating from background.

It is enabled to use location background mode on IOS. It works in background without any problem, even for days, it does what it has to do. But when I open the app after a longer time period (about one day or more) working in background, the UI is frozen! Note, if I do it after some hours, it is okkey, the problem comes after a longer period.

Flutter version: [✓] Flutter (Channel stable, 1.20.1, on Mac OS X 10.15.5 19F101, locale hu-HU)

What can I do to fix it? Should I re-init UI somehow in Flutter? Or do anything from native side?

Thanks a lot, any help is highly appriciated!

Tom
  • 3,899
  • 22
  • 78
  • 137

3 Answers3

4

Make sure that the state of your app is cached some way after entering background. It might not be in memory any more after a longer period of time and your UI is unable to render without it.

The issue does not seem to be related to background location fetching - try isolating that problem by running your app on a real device with debug enabled. Switch it to background and open some memory hungry apps to force your app's termination. After that open the app and check the logs, there should be some kind of indication what caused the Flutter UI freeze.

mgapinski
  • 483
  • 2
  • 7
  • It is related with background location fetching. If I comment it out, the app does not freeze after opening it. Thanks a lot for your supoort! – Tom Aug 18 '20 at 11:32
  • If it's the case you'll need to give implementation details, eg. what plugin did you use in flutter, check if all background modes are enabled in Xcode etc. Given recent changes in location apis on iOS I would recommend checking if the plugin does not use any deprecated stuff – mgapinski Aug 18 '20 at 12:05
  • Try to capture logs in the way I told you without removing the location stuff -> there has to be something there – mgapinski Aug 18 '20 at 12:07
3

Last time I faced this issue on both ios and android it was actually related to my state manager which was provider package. I finally managed it by saving data in sqlite when app goes to background and flushing provider itself and re initiate state each time that app opens from task manager.

1

After updating Flutter to 1.20.3, this bug is fixed!

Tom
  • 3,899
  • 22
  • 78
  • 137