Unsolved Qt Positioning not working in iOS
-
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 returningQGeoPositionInfoSource::UnknownSourceError
.Any idea why it doesn't work? I am using Qt 5.5.1, latest Xcode (7.1.1) and iOS (9.1).
-
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 ?
-
@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. -
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(); }
-
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?
-
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 -
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? -
Maybe try examples available, like: "Weather Info"?
-
Weather info doesn't work either. It just shows "Loading weather data" indefinitely.
-
What version of iOS and Xcode are you using ? (latest can change pretty quickly)
-
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).
-
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
-
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.
-
@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.
-
IOS10.2
work only simulator, on device not workQGeoPositionInfoSource::createDefaultSource(0) is NULL
-
Did you got asked for permission ?
-
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 -
@SGaist
ask permision only simulator
on real device dont ask -
Then check that you allowed the GPS to be used.
-
@SGaist where check?
in device Settings->Privacy->Location Service
there is no my application