Software Development

How do I handle background geolocation updates in Flutter for a delivery app?

WI Asked by William Taylor · 15-01-2025
0 upvotes 11,275 views 0 comments
The question

I'm building a real-time tracking feature for a delivery platform. On Android, it works fine, but on iOS, the app gets suspended after a few minutes in the background. What is the most reliable way to maintain a persistent connection or local updates without the OS killing the process? I need this to be battery-efficient but accurate enough for GPS tracking.

3 answers

0
JE
Answered on 17-01-2025

Handling iOS background tasks is notoriously strict. To keep it alive, you need to enable 'Location updates' and 'Background fetch' in XCode's Capabilities. I highly recommend using the 'flutter_background_geolocation' package by Transistor Software. While it is a paid plugin for certain use cases, it is the only one that reliably handles the complex lifecycle of iOS and Android "Doze" modes. In my 2023 project, we tried the free alternatives, but they all failed when the user force-quit the app or when the battery saver kicked in during a long delivery run.

0
TH
Answered on 18-01-2025

Have you considered using a "Headless" task approach? Most developers forget that the UI isolate is destroyed when the app is in the background, so your logic must live in a separate entry point.

WI 20-01-2025

Thomas, I am using 'flutter_background_service', but I'm having trouble sharing data between the background isolate and the main UI. Should I be using a local database like Hive or SharedPreferences to bridge the gap? I’m worried that writing to disk every 10 seconds for a GPS coordinate might be too much for the storage or the battery. What’s your experience with that?

0
BA
Answered on 21-01-2025

Make sure you are requesting 'Always' permission, not just 'While in Use'. iOS will aggressively kill the location stream if the permission doesn't match the background usage.

JE 22-01-2025

Barbara is right; the permission level is critical. Also, William, for the data sharing, definitely use Hive—it's fast enough that the overhead is negligible for simple coordinates.

Share your thoughts

Your email address will not be published. Required fields are marked (*)

Professional Counselling Session

Still have questions?
Schedule a free counselling session

Our experts are ready to help you with any questions about courses, admissions, or career paths. Get personalized guidance from industry professionals.

Request a Call Back

Search Online

We Accept

We Accept

Follow Us

"PMI®", "PMBOK®", "PMP®", "CAPM®" and "PMI-ACP®" are registered marks of the Project Management Institute, Inc. | "CSM", "CST" are Registered Trade Marks of The Scrum Alliance, USA. | COBIT® is a trademark of ISACA® registered in the United States and other countries.

Book Free Session