summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTimur Pocheptsov <timur.pocheptsov@qt.io>2018-10-19 08:31:00 +0200
committerTimur Pocheptsov <timur.pocheptsov@qt.io>2018-10-22 13:06:28 +0000
commit448b3a35cea27878a3123ec7e40f875032dd3267 (patch)
tree3e6c76b0b2f795421cfa0e3a4fddbb6f4113b526 /src
parent0cdf4748dd40ec2e0df20eda4a63e8e070d2b790 (diff)
downloadqtlocation-448b3a35cea27878a3123ec7e40f875032dd3267.tar.gz
CoreLocation: fix unconditional (previously) method calls
that result in a warning nowadays, saying we must have a description in Info.plist to be able to call these methods. Task-number: QTBUG-41827 Change-Id: Ib1997a609553345358aded419a403582ccfdc0fb Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
Diffstat (limited to 'src')
-rw-r--r--src/plugins/position/corelocation/qgeopositioninfosource_cl.mm27
1 files changed, 19 insertions, 8 deletions
diff --git a/src/plugins/position/corelocation/qgeopositioninfosource_cl.mm b/src/plugins/position/corelocation/qgeopositioninfosource_cl.mm
index 993e7501..6435963b 100644
--- a/src/plugins/position/corelocation/qgeopositioninfosource_cl.mm
+++ b/src/plugins/position/corelocation/qgeopositioninfosource_cl.mm
@@ -194,18 +194,29 @@ bool QGeoPositionInfoSourceCL::enableLocationManager()
m_locationManager.desiredAccuracy = kCLLocationAccuracyBest;
m_locationManager.delegate = [[PositionLocationDelegate alloc] initWithInfoSource:this];
- // These two methods are new in iOS 8. They require NSLocationAlwaysUsageDescription
- // and NSLocationWhenInUseUsageDescription to be set in Info.plist to work (methods are
- // noop if there are no such entries in plist).
+ // -requestAlwaysAuthorization is available on iOS (>= 8.0) and watchOS (>= 2.0).
+ // This method requires both NSLocationAlwaysAndWhenInUseUsageDescription and
+ // NSLocationWhenInUseUsageDescription entries present in Info.plist (otherwise,
+ // while probably a noop, the call generates a warning).
+ // -requestWhenInUseAuthorization only requires NSLocationWhenInUseUsageDescription
+ // entry in Info.plist (available on iOS (>= 8.0), tvOS (>= 9.0) and watchOS (>= 2.0).
+
#ifndef Q_OS_MACOS
+ NSDictionary<NSString *, id> *infoDict = NSBundle.mainBundle.infoDictionary;
+ const bool hasAlwaysUseUsage = !![infoDict objectForKey:@"NSLocationAlwaysAndWhenInUseUsageDescription"];
+ const bool hasWhenInUseUsage = !![infoDict objectForKey:@"NSLocationWhenInUseUsageDescription"];
#ifndef Q_OS_TVOS
- [m_locationManager requestAlwaysAuthorization];
-#endif
- [m_locationManager requestWhenInUseAuthorization];
-#endif
+ if (hasAlwaysUseUsage && hasWhenInUseUsage)
+ [m_locationManager requestAlwaysAuthorization];
+ else
+#endif // !Q_OS_TVOS
+ if (hasWhenInUseUsage)
+ [m_locationManager requestWhenInUseAuthorization];
+#endif // !Q_OS_MACOS
+
}
- return (m_locationManager != 0);
+ return (m_locationManager != nullptr);
}
void QGeoPositionInfoSourceCL::setTimeoutInterval(int msec)