Getting GPS data in background mode on iOS with Qt app
-
Hi all
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 :(
Best,
Marek -
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
-
Hi
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.
Any idea?Best,
Marek -
@Marek
well you can ask the os for more background timebut 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
https://developer.apple.com/documentation/uikit/app_and_scenes/preparing_your_ui_to_run_in_the_background/about_the_background_execution_sequenceHowever, how should I know how these iOS system requests are translated into Qt libs ?
There are applicaions like Strava
https://apps.apple.com/us/app/strava-run-ride-swim/id426826309
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 ?
Best,
Marek -
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
https://developer.apple.com/documentation/uikit/app_and_scenes/preparing_your_ui_to_run_in_the_background/about_the_background_execution_sequence
"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 ?Best,
Marek -
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?
--Sam
-
@BTSTOnline Hi
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 ?Best,
Marek -
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.
[EDIT 25-10-2022]: For clarification (because I stumbled upon this problem again): On iOS and Android Qt signals are not processed when the app is backgrounded meaning they get queued and processed when the app gets active again. On Android you can use a background service using Qt code internally. On iOS you cannot rely on Qt due to signals not being processed (even when the system activated the app for background processing). This means that you have to use obj-c code for all background processing modes (Bluetooth, GPS, etc.).
-
@hamer said in Getting GPS data in background mode on iOS with Qt app:
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"