flutter-geolocator icon indicating copy to clipboard operation
flutter-geolocator copied to clipboard

iOS background task terminating after period of time

Open bujdy opened this issue 3 years ago • 6 comments

🐛 Bug Report

When i have enabled foregroundNotificationConfig and i am using app for longer time lets say one day (app is running but in minimized state), location tracking wont work. I managed to find log when app is running longer than 30 seconds: [BackgroundTask] Background Task 54 ("Flutter debug task"), was created over 30 seconds ago. In applications running in the background, this creates a risk of termination. Remember to call UIApplication.endBackgroundTask(_:) for your task in a timely manner to avoid this. So probably it will terminate because of this. Is it possible to somehow make that background task longer?

Expected behavior

Tracking user if he minimize app / put phone to sleep for whole day (for example).

Reproduction steps

None

Configuration

Same as example

Version: 8.2.0

Platform:

  • [x] :iphone: iOS

bujdy avatar Apr 11 '22 07:04 bujdy

this is happening in the android devices too.

prabuddaFernando avatar Apr 12 '22 14:04 prabuddaFernando

@mvanbeusekom Any ideas?

JulianBissekkou avatar May 24 '22 12:05 JulianBissekkou

anyone tried to debug this? @mvanbeusekom

bujdy avatar Jun 18 '22 17:06 bujdy

Did anyone of the participants in this thread found a solution or workaround to this problem?

JulianBissekkou avatar Aug 09 '22 13:08 JulianBissekkou

This might be related to #1122

JulianBissekkou avatar Aug 17 '22 15:08 JulianBissekkou

My guess is that Android eventually kills the activity hosting the Flutter engine. Using the foreground config just elevates the priority of the MainActivity making it less likely that Android will kill the application but it does not prevent it entirely. Foreground config is there mostly to help with short lived tasks where users may be switching between applications etc and you still want to keep the location tracking active. For much longer periods a library like flutter_foreground_task should be used where an entirely new Flutter engine is created in an Android foreground service that can live without the main activity and engine. It does make it a bit more complicated to work with. @mvanbeusekom maybe we should just update the description of the foreground config on the Android settings to state this?

Wackymax avatar Sep 03 '22 06:09 Wackymax

So this issue is related with the flutter-debug job? I am developing background mode related app and got this message.

[BackgroundTask] Background Task 3 ("Flutter debug task"), was created over 30 seconds ago.
In applications running in the background, this creates a risk of termination. 
Remember to call UIApplication.endBackgroundTask(_:) for your task in a timely manner to avoid this.

At a glance, I thought that I implemented native side in a wrong way.

kitoheedong avatar Sep 23 '22 09:09 kitoheedong

Dear @bujdy,

Can you share some of your minimal reproducible code or an example project? Furthermore, it is unclear to me if this happens after approx 30 seconds or one day. Did you also implemented all the steps from the README regarding background location. And, @prabuddaFernando, have you added: in your manifest file, and followed the steps in the README?

Kind regards,

TimHoogstrate avatar Aug 21 '23 07:08 TimHoogstrate

Without additional information, we are unfortunately not able to resolve this issue. Therefore, we reluctantly closed this issue for now. If you run into this issue later, feel free to file a new issue with a reference to this issue. Add a description of detailed steps to reproduce, expected and current behaviour, logs and the output of 'flutter doctor -v'. Thanks for your contribution.

github-actions[bot] avatar Sep 04 '23 08:09 github-actions[bot]

Any updates of it? i am getting this error Runner[3633:1051724] [BackgroundTask] Background Task 144 ("Flutter debug task"), was created over 30 seconds ago. In applications running in the background, this creates a risk of termination. Remember to call UIApplication.endBackgroundTask(_:) for your task in a timely manner to avoid this.

i created a background fetch and i tried to simulate it using xcode but i got this error. Any idea?

DavidIjsud avatar Jan 29 '24 18:01 DavidIjsud