-
Notifications
You must be signed in to change notification settings - Fork 124
IOS foreground task stops working after around 35 seconds #18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Hi, @MenuItem207 I tested it and found the same problem. It seems to be a background processing limitation on the iOS platform. I will check other ways to solve the problem. |
One good news is that you can continue to receive updates by subscribing to the stream on Please check this code: // The callback function should always be a top-level function.
void startCallback() {
// The setTaskHandler function must be called to handle the task in the background.
FlutterForegroundTask.setTaskHandler(FirstTaskHandler());
}
class FirstTaskHandler implements TaskHandler {
StreamSubscription<Position>? streamSubscription;
@override
Future<void> onStart(DateTime timestamp, SendPort? sendPort) async {
final positionStream = Geolocator.getPositionStream();
streamSubscription = positionStream.listen((event) {
// Update notification content.
FlutterForegroundTask.updateService(
notificationTitle: 'Current Position',
notificationText: '${event.latitude}, ${event.longitude}');
// Send data to the main isolate.
sendPort?.send(event);
});
}
@override
Future<void> onEvent(DateTime timestamp, SendPort? sendPort) async {
}
@override
Future<void> onDestroy(DateTime timestamp) async {
await streamSubscription?.cancel();
}
} And add the following to your info.plist file:
Importantly, the user must select |
Alright, the foreground task seems to be working fine now! All I did was add the fetch line to my UIBackground modes. Although for reference, the location permission I'm using is Always and not while using App |
@Dev-hwang , can you add this in Docs as well , might be usefull for Native android devlopers like me who dont have much knowledge of IOS , took lot of time to figure out why my bluetooth tasks were stoping after minimising app , even when all settings was done properly <key>UIBackgroundModes</key>
<array>
<string>fetch</string>
<string>location</string>
</array> |
@Dev-hwang
|
I've been using this package for my app and the implementation works fine on Android. However I've noticed that after about 35 seconds of swiping out of the app to the Home Screen, the foreground service stops updating. I'm using geolocator to get the location like so:
locationSubscription = positionStream.listen((Position position) { currentLocation = position; FlutterForegroundTask.updateService( notificationTitle: 'Current Position', notificationText: '${position.latitude}, ${position.longitude}'); })
The foreground service updates for about 35 seconds but stops after that. The
WithForegroundTask
widget has been wrapped around my home widget and I'm using the IOS simulator to test this. I understand the readme did mention that 'If the app is forcibly closed, the task will not work.' I'm not sure if this is a misunderstanding on my part but swiping out to the Home Screen isn't force closing the app right?Tldr: the flutter foreground task stops updating after about 35 seconds on the iOS simulator
The text was updated successfully, but these errors were encountered: