summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaolo Angelelli <paolo.angelelli@qt.io>2018-09-06 12:47:31 +0200
committerPaolo Angelelli <paolo.angelelli@qt.io>2018-09-18 09:48:03 +0000
commitf151773aa749eadd7adb35fbd8f727238152da4f (patch)
tree59fbc4c5364d55e69fc7a0acb97d8abc6dab121d
parent4ef6b50278c041336f794cef20dd7e30fe8fbec0 (diff)
downloadqtlocation-f151773aa749eadd7adb35fbd8f727238152da4f.tar.gz
Check authorization in QGeoPositionInfoSourceCL::enableLocationManager
Task-number: QTBUG-52660 Change-Id: I528bde71dd0ad5ad58e26a9d484364b35b6c4b62 Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io>
-rw-r--r--src/plugins/position/corelocation/qgeopositioninfosource_cl.mm34
1 files changed, 33 insertions, 1 deletions
diff --git a/src/plugins/position/corelocation/qgeopositioninfosource_cl.mm b/src/plugins/position/corelocation/qgeopositioninfosource_cl.mm
index e078c3b0..993e7501 100644
--- a/src/plugins/position/corelocation/qgeopositioninfosource_cl.mm
+++ b/src/plugins/position/corelocation/qgeopositioninfosource_cl.mm
@@ -140,7 +140,39 @@ void QGeoPositionInfoSourceCL::setUpdateInterval(int msec)
bool QGeoPositionInfoSourceCL::enableLocationManager()
{
if (!m_locationManager) {
- m_locationManager = [[CLLocationManager alloc] init];
+ if ([CLLocationManager locationServicesEnabled]) {
+ // Location Services Are Enabled
+ switch ([CLLocationManager authorizationStatus]) {
+ case kCLAuthorizationStatusNotDetermined:
+ // User has not yet made a choice with regards to this application
+ break;
+ case kCLAuthorizationStatusRestricted:
+ // This application is not authorized to use location services. Due
+ // to active restrictions on location services, the user cannot change
+ // this status, and may not have personally denied authorization
+ return false;
+ case kCLAuthorizationStatusDenied:
+ // User has explicitly denied authorization for this application, or
+ // location services are disabled in Settings
+ return false;
+ case kCLAuthorizationStatusAuthorizedAlways:
+ // This app is authorized to start location services at any time.
+ break;
+#ifndef Q_OS_MACOS
+ case kCLAuthorizationStatusAuthorizedWhenInUse:
+ // This app is authorized to start most location services while running in the foreground.
+ break;
+#endif
+ default:
+ // By default, try to enable it
+ break;
+ }
+ } else {
+ // Location Services Disabled
+ return false;
+ }
+
+ m_locationManager = [[CLLocationManager alloc] init];
#if defined(Q_OS_IOS) || defined(Q_OS_WATCHOS)
if (__builtin_available(watchOS 4.0, *)) {