I want to implement some kind of background job / checking in my Flutter app, but I notice this weird behaviour on iOS.
When I start this timer and I am still in the app, everything works just fine, but when I return from the app to home screen, this callback is executed for five times and then it stops. On android in the other hand, it runs all the time, even if I am on the home screen.
I add this "permissions" in info.plist, but it still stops after few attempts.
<key>UIBackgroundModes</key>
<array>
<string>fetch</string>
<string>processing</string>
<string>remote-notification</string>
</array>
I also tried this package (https://pub.dev/packages/workmanager), but doesn't worked for me.
Here is my function that should be executed
Timer.periodic(const Duration(seconds: 30), (_) async {
var parkingLots = await DataService().getFreePlaces();
if (parkingLots[parkingLotId] == 0) {
print("full");
} else {
print("job is running");
}
print(parkingLots[parkingLotId]);
});
Basically, it should every 30 second check if parking lot has some free places and if not, it should send a notification to the user.
Do you have any idea, how to make this work? Or do you have any suggestions how to do this?
Thank you