Reputation: 739
I need to obtain device current location information with Qt/Qml/Quick and C++ on Mac OS X. I test it:
PositionSource {
id: src
updateInterval: 60000
active: true
preferredPositioningMethods: PositionSource.AllPositioningMethods
Component.onCompleted: {
src.start()
src.update()
var supPos = "Unknown"
if (src.supportedPositioningMethods == PositionSource.NoPositioningMethods) {
supPos = "NoPositioningMethods"
} else if (src.supportedPositioningMethods == PositionSource.AllPositioningMethods) {
supPos = "AllPositioningMethods"
} else if (src.supportedPositioningMethods == PositionSource.SatellitePositioningMethods) {
supPos = "SatellitePositioningMethods"
} else if (src.supportedPositioningMethods == PositionSource.NonSatellitePositioningMethods) {
supPos = "NonSatellitePositioningMethods"
}
console.log("Position Source Loaded || Supported: "+supPos+" Valid: "+valid);
}
onPositionChanged: {
var coord = src.position.coordinate;
console.log("Coordinate:", coord.longitude, coord.latitude);
backend.longitude = coord.longitude;
backend.latitude = coord.latitude;
console.log(src.nmeaSource)
}
}
When I run it on Qt Creator, I get this this ok/cancel popup : "TestApp" would like to use your current location.". if I click ok button, it can obtain current device location information (latitude, longitude, etc.)
On the other hand, when I try to run app on terminal (path: TestApp.app/Content/MacOs/TestApp) or deploy with "macqdeploy", the popup didn't appear and it can't obtain current location.
For deployment, I also test copying all Qt/Qml/QuickControl libs/frameworks to bundle manually, but it also doesn't work.
I should deploy my application, so location information is necesarry. How can I solve this problem? How can get privileges popup again?
Thanks!
Edit:
This is my Info.plist:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>LSUIElement</key>
<string>1</string>
<key>NSLocationAlwaysUsageDescription</key>
<string>app2.app always location use</string>
</dict>
</plist>
Upvotes: 0
Views: 898
Reputation: 4582
You need a property list info.plist
file in your project if you don't have one. I think starting from iOS10 /macOS10 this file controls permissions. Refer to Apple's guide About Info.plist Keys and Values
for details.
In your case, I think you need this entry in your info.plist
file:
<key>NSLocationAlwaysUsageDescription</key>
<string>${PRODUCT_NAME} always location use</string>
the following SO posts might be help:
Location Services not working in iOS 8
NSLocationAlwaysUsageDescription string added in info.plist
Upvotes: 0