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. Qt Positioning not working in iOS
Forum Updated to NodeBB v4.3 + New Features

Qt Positioning not working in iOS

Scheduled Pinned Locked Moved Unsolved Mobile and Embedded
21 Posts 7 Posters 8.0k Views 2 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
    m_andrej
    wrote on last edited by m_andrej
    #1

    Hello,
    I added some Qt positioning code to my application:

    m_geoSource = QGeoPositionInfoSource::createDefaultSource(this);
    if(m_geoSource) {
        connect(m_geoSource, &QGeoPositionInfoSource::positionUpdated,
                this, &OfficesModel::onPositionUpdated);
        m_geoSource->startUpdates();
    }
    

    It's in a constructor of a QObject subclass, the slot onPositionUpdated simply prints the coordinates. The application works perfectly on Android, but on iOS the signal positionUpdated() is never emitted. I already tried m_geoSource->setUpdateInterval(5000);, but it doesn't help.

    BTW m_geoSource->error() keeps returning QGeoPositionInfoSource::UnknownSourceError.

    Any idea why it doesn't work? I am using Qt 5.5.1, latest Xcode (7.1.1) and iOS (9.1).

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      I haven't used that module yet but what comes to mind (might be silly though): do you have the GPS on and is your application allowed to use it ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • M Offline
        M Offline
        m_andrej
        wrote on last edited by
        #3

        @SGaist said:

        do you have the GPS on?

        Yes, other apps which require geographic coordinates are working fine.

        @SGaist said:

        and is your application allowed to use it ?

        I added the following to my Info.plist:

        <key>UIRequiredDeviceCapabilities</key>
        <array>
        	<string>location-services</string>
        	<string>gps</string>
        </array>
        

        and it still doesn't work. However, on iOS the location permission is requested from user the first time the application requires location, not when it's being installed (like on Android). In my case I don't get any dialog when QGeoPositionInfoSource instance is created. So maybe I should add some Objective-C code also, if Qt doesn't handle this. But it would mean that Qt Positioning isn't truly cross-platform. I'll dig deeper and let you know.

        1 Reply Last reply
        0
        • K Offline
          K Offline
          kolegs
          wrote on last edited by
          #4

          Did you set update interval?

          m_geoSource->setUpdateInterval(1000);
          

          Btw, thats my code and it works on ios

          QGeoPositionInfoSource *source = QGeoPositionInfoSource::createDefaultSource(0);
          
              if (source) {
                  //here set up your update interval in msecs
                  source->setUpdateInterval(1000);// 1 second
                  connect(source, SIGNAL(positionUpdated(QGeoPositionInfo)),
                          this, SLOT(positionUpdated(QGeoPositionInfo)));
                  source->startUpdates();
              }
          
          1 Reply Last reply
          1
          • M Offline
            M Offline
            m_andrej
            wrote on last edited by
            #5

            Yes, I tried that as well (see the first post). But thanks for this post, I will try once again with a completely blank project.

            BTW how does your code work? Do you get a system dialog asking for permission for location when the application attempts to get the first position?

            1 Reply Last reply
            0
            • K Offline
              K Offline
              kolegs
              wrote on last edited by kolegs
              #6

              I ask for the location at the begining of the program so it shows same time application starts.
              Btw I did not add anything to my Info.plist, so I am not sure if it is required

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

                I tried again with a Hello world application from scratch. It still doesn't work. I didn't write a particular info.plist, so it was autogenerated by qmake. Application starts normally, but I don't get any dialog asking for permission to provide location and of course positionUpdated() still isn't emitted.

                I tried both real device and iOS Simulator with simulated location.
                Any ideas what else I should try?

                1 Reply Last reply
                0
                • K Offline
                  K Offline
                  kolegs
                  wrote on last edited by kolegs
                  #8

                  Maybe try examples available, like: "Weather Info"?

                  1 Reply Last reply
                  0
                  • M Offline
                    M Offline
                    m_andrej
                    wrote on last edited by
                    #9

                    Weather info doesn't work either. It just shows "Loading weather data" indefinitely.

                    1 Reply Last reply
                    0
                    • SGaistS Offline
                      SGaistS Offline
                      SGaist
                      Lifetime Qt Champion
                      wrote on last edited by
                      #10

                      What version of iOS and Xcode are you using ? (latest can change pretty quickly)

                      Interested in AI ? www.idiap.ch
                      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                      M 1 Reply Last reply
                      0
                      • SGaistS SGaist

                        What version of iOS and Xcode are you using ? (latest can change pretty quickly)

                        M Offline
                        M Offline
                        m_andrej
                        wrote on last edited by
                        #11

                        I have Xcode 7.1.1 and iOS 9.1 both on device and simulator. I added this information to the first post.

                        I already verified that I can make a Hello World iOS app in XCode, which successfully obtains user position using native code (CLLocationManager).

                        1 Reply Last reply
                        0
                        • L Offline
                          L Offline
                          ldanzinger
                          wrote on last edited by
                          #12

                          You might need to add the following keys to your plist

                          • NSLocationAlwaysUsageDescription
                          • NSLocationWhenInUseUsageDescription

                          You also may need to add either of the following to your project file

                          QT += positioning sensors

                          TavisT 1 Reply Last reply
                          2
                          • M Offline
                            M Offline
                            m_andrej
                            wrote on last edited by m_andrej
                            #13

                            I already implemented this using native code. But thanks. Maybe this helps somebody else.

                            BTW I used the class CLLocationManager-blocks (https://github.com/axldyb/CLLocationManager-blocks). Thanks to this I was able to implement it by a brief Objective-C snippet in a QObject subclass. The position-update-handler was just an objective-C Block rather than Delegate. Writing the Delegate would have required to subclass NSObject.

                            1 Reply Last reply
                            0
                            • L ldanzinger

                              You might need to add the following keys to your plist

                              • NSLocationAlwaysUsageDescription
                              • NSLocationWhenInUseUsageDescription

                              You also may need to add either of the following to your project file

                              QT += positioning sensors

                              TavisT Offline
                              TavisT Offline
                              Tavis
                              wrote on last edited by
                              #14

                              @ldanzinger All you need to do in order to get QTPositioning to work is add <key>NSLocationAlwaysUsageDescription</key>
                              to your info.plist file.

                              create an iOS folder in the root of your project and place your info.plist file in there then add the following to you .pro file

                              ios {
                              QMAKE_INFO_PLIST = ios/Info.plist
                              }

                              This fixes the geoflickr example qt quick app.

                              1 Reply Last reply
                              0
                              • B Offline
                                B Offline
                                beak
                                wrote on last edited by
                                #15

                                IOS10.2
                                work only simulator, on device not work

                                QGeoPositionInfoSource::createDefaultSource(0) is NULL
                                1 Reply Last reply
                                0
                                • SGaistS Offline
                                  SGaistS Offline
                                  SGaist
                                  Lifetime Qt Champion
                                  wrote on last edited by
                                  #16

                                  Did you got asked for permission ?

                                  Interested in AI ? www.idiap.ch
                                  Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                                  B 1 Reply Last reply
                                  1
                                  • E Offline
                                    E Offline
                                    ealltech
                                    wrote on last edited by
                                    #17

                                    I ask for the location at the begining of the program so it shows same time application starts.
                                    Btw I did not add anything to my Info.plist, so I am not sure if it is required

                                    1 Reply Last reply
                                    0
                                    • SGaistS SGaist

                                      Did you got asked for permission ?

                                      B Offline
                                      B Offline
                                      beak
                                      wrote on last edited by
                                      #18

                                      @SGaist
                                      ask permision only simulator
                                      on real device dont ask

                                      1 Reply Last reply
                                      0
                                      • SGaistS Offline
                                        SGaistS Offline
                                        SGaist
                                        Lifetime Qt Champion
                                        wrote on last edited by
                                        #19

                                        Then check that you allowed the GPS to be used.

                                        Interested in AI ? www.idiap.ch
                                        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                                        B 1 Reply Last reply
                                        0
                                        • SGaistS SGaist

                                          Then check that you allowed the GPS to be used.

                                          B Offline
                                          B Offline
                                          beak
                                          wrote on last edited by
                                          #20

                                          @SGaist where check?
                                          in device Settings->Privacy->Location Service
                                          there is no my application

                                          1 Reply Last reply
                                          0

                                          • Login

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