Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
Getting GPS data in background mode on iOS with Qt app
Location updates stops being delivered to application in background after about a 20 minutes. Application is not closed because when I click on app icon it is brought back from background in state I left it and then updates starts comming again. I can also see that in top right corner of task bar there is little arrow, when it is displayed I got the updates, when it disappears I'm not receiving updates. I'm getting GPS data every 5 seconds, keep it in some queue and every minute I connect to my server via tcp socket and send these updates. When top right arrow disappears my app no longer connects to the server (and it should even with empty data) so I assume that app is in some suspend mode.
I have written app in Qt/QML and then converted the project to XCode. I have checked "Background Modes" (Location updates, Background fetch) in Capabilities. I have in plist file UIBackgroundModes fetch,location. I have also NSLocationWhenInUse NSLocationAlways and NSLocationAlwaysAndWhenInUse UsageDescription and App in system checking has settings->myapp->location->Always
I'm testing on iOS 12.3.1 and with Qt 5.12.3
I have asked this question on stackoverflow but with no luck :(
@Marek I don't know how it is done in iOS, on Android you need to implement a background service. My guess is that on iOS it is similar. You should check iOS developer documentation.
that process is not as easy on iOS as on android
for now you can declare your app as a UIBackgroundMode via info.plist file
but good luck getting that on the AppStore, the process is tedious
Thanks for answer. Taking advantage of Qt my app is running on Android and iOS.
On Android it works flawlessly with Android services.
On iOS I know about UIBackgroundMode and I have turned this on. But the problem is that after 20 minutes application freezes, updates are not delivered, though app is no closed.
well you can ask the os for more background time
but an unlimited amount like on android is, to my knowledge not possible.
There should be a way, otherwise music apps would be able to play in the background, but I don't know where to look for that, sry.
At first I thought my code will work. When app has entered background there was a iOS question: "App is using your location in background, do you agree?" I hit YES and this was a good sign, but only for some 20 minutes.
I'm not sure about longer execution time, after all it only needs to collect GPS data.
Fetch background mode says system will wake up app periodically when conditions are good (network and power conditions) and I can use setMinimumBackgroundFetchInterval
Here is the use case with exactly what I want
However, how should I know how these iOS system requests are translated into Qt libs ?
There are applicaions like Strava
That can record your position during activity so there must be a way to do it.
When I submitted the app to AppStore they have rejected it with information that I have background mode enabled but the app has no functionality to use it, I have explained them how it works and I'm waiting for reply.
Are here developers writing apps especially for iOS ?
Maybe I should write the part of receiving GPS data and possibly sending updates in Objective_c ?
Just a word of explanation how my app works.
I need to track user position when user hits on app some button "track position".
On Android when he does that I start Android Service. When user turns off this function in App, I just stop Android Service
On iOS from what I understand I declare that I want location updates during application build so they will be delivered whether I need them or not - right ?
According to this information
"If your app is not running when an event arrives, the system launches the app and moves it directly to the background" - this is somehow crazy, when I don't need location updates because user does not select this with "track position" button app will be launched anyway ?
BTSTOnline last edited by
I am doing this on iOS without issues... passed the review and published to the App Store.
I do use ObjC to get the updates and push them out to C++ for the app...
However, my issue is now with Android. Can you share how you do the background position in Android?
Lets help each other.
I have this running without problem on Android, I'm using some JNI and Java
On iOS it does not work for me, actually it stops working after about 20 minutes, but I do not use ObjC and maybe don't understand how this was designed by Apple
Can you reach me via email marek.florianczyk at gmail.com ?
hamer last edited by hamer
The problem is that Qt signals are not processed when the app is backgrounded. The only solution we found is to implement a custom location manager for iOS using Objective-C and CLLocationManager.
The problem is that Qt signals are not processed when the app is backgrounded
Yes, because applications in background are stopped by the OS. On Android you have to implement a background service, not sure about iOS.
Here's a very good post about iOS "background services"