Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. Getting GPS data in background mode on iOS with Qt app
Forum Updated to NodeBB v4.3 + New Features

Getting GPS data in background mode on iOS with Qt app

Scheduled Pinned Locked Moved Unsolved Mobile and Embedded
12 Posts 5 Posters 2.6k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Marek
    wrote on last edited by
    #1

    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

    jsulmJ J.HilkJ 2 Replies Last reply
    0
    • M Marek

      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

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @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.

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • M Marek

        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

        J.HilkJ Offline
        J.HilkJ Offline
        J.Hilk
        Moderators
        wrote on last edited by
        #3

        @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

        https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/iPhoneOSKeys.html#//apple_ref/doc/uid/TP40009252-SW22

        but good luck getting that on the AppStore, the process is tedious


        Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


        Q: What's that?
        A: It's blue light.
        Q: What does it do?
        A: It turns blue.

        1 Reply Last reply
        1
        • M Offline
          M Offline
          Marek
          wrote on last edited by
          #4

          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

          J.HilkJ 1 Reply Last reply
          0
          • M Marek

            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

            J.HilkJ Offline
            J.HilkJ Offline
            J.Hilk
            Moderators
            wrote on last edited by
            #5

            @Marek
            well you can ask the os for more background time

            https://developer.apple.com/documentation/uikit/app_and_scenes/preparing_your_ui_to_run_in_the_background/extending_your_app_s_background_execution_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.


            Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


            Q: What's that?
            A: It's blue light.
            Q: What does it do?
            A: It turns blue.

            1 Reply Last reply
            0
            • M Offline
              M Offline
              Marek
              wrote on last edited by
              #6

              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_sequence

              However, 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

              1 Reply Last reply
              0
              • M Offline
                M Offline
                Marek
                wrote on last edited by
                #7

                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

                1 Reply Last reply
                0
                • B Offline
                  B Offline
                  BTSTOnline
                  wrote on last edited by
                  #8

                  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

                  M 1 Reply Last reply
                  0
                  • B BTSTOnline

                    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

                    M Offline
                    M Offline
                    Marek
                    wrote on last edited by
                    #9

                    @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

                    1 Reply Last reply
                    0
                    • H Offline
                      H Offline
                      hamer
                      wrote on last edited by hamer
                      #10

                      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.).

                      jsulmJ 1 Reply Last reply
                      0
                      • H 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.

                        [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.).

                        jsulmJ Offline
                        jsulmJ Offline
                        jsulm
                        Lifetime Qt Champion
                        wrote on last edited by
                        #11

                        @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.

                        https://forum.qt.io/topic/113070/qt-code-of-conduct

                        1 Reply Last reply
                        0
                        • J.HilkJ Offline
                          J.HilkJ Offline
                          J.Hilk
                          Moderators
                          wrote on last edited by
                          #12

                          Here's a very good post about iOS "background services"

                          https://stackoverflow.com/a/11044108


                          Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


                          Q: What's that?
                          A: It's blue light.
                          Q: What does it do?
                          A: It turns blue.

                          1 Reply Last reply
                          2

                          • Login

                          • Login or register to search.
                          • First post
                            Last post
                          0
                          • Categories
                          • Recent
                          • Tags
                          • Popular
                          • Users
                          • Groups
                          • Search
                          • Get Qt Extensions
                          • Unsolved