Dev-hwang / flutter_foreground_task

This plugin is used to implement a foreground service on the Android platform.
https://pub.dev/packages/flutter_foreground_task
MIT License
149 stars 109 forks source link

Foreground Task Doesn't Work on iOS #257

Closed alperenbaskaya58 closed 2 months ago

alperenbaskaya58 commented 2 months ago

Hi, We are trying to fetch data from API on interval given to Foreground task. Despite it shows as started, nothing happens on interval or sometimes. Perfectly works on android but we have tried --release mode on our real device iphone 14 pro nothing happens. Only when user interacts with notification from foreground task it fires _onReceiveTaskData but it ends with count 3. Then no notification comes.

We tried to reproduce example app. Enabled background fetch, background processing. Declared that works fine on foreground but does not work. Is there anything except from it?

Dev-hwang commented 2 months ago

Does the example work fine in debug mode?

alperenbaskaya58 commented 2 months ago

It works same as debug mode. I need to ask it, if we leave app and use another apps is not it expected to run along? It works like count 5ish and stops the work on example app debug mode. Dev call stack shows 'startCallback' stack as paused.

Dev-hwang commented 2 months ago

no. using another app means that the app running the task has entered the background state.

check this plugin limitations.

if the app can't perform tasks at the exact time, but you want to run it periodically in the background, try this flutter_background_service.

alperenbaskaya58 commented 2 months ago

Okay, thanks for informing me about these states. I know background service interval can not be less than 15 minutes. Is scheduling local notifications then make operations under the notifs working to decrease fetching interval like 30 seconds or is there any limitations again? Or does rooting the phone work?

Dev-hwang commented 2 months ago

@alperenbaskaya58

This plugin does not implement BGTaskScheduler. I simply used Timer.scheduledTimer to allow short interval while the app is in use. Timer.scheduledTimer only runs in the background for about 30 seconds. This is a limitation of iOS. You must return to the app to continue working.

https://github.com/Dev-hwang/flutter_foreground_task/blob/a61fbcbf6208239fc698ef0f9427fa036719e6e6/ios/Classes/service/BackgroundService.swift#L305