diff options
author | Andy Shaw <andy.shaw@qt.io> | 2019-11-06 06:58:16 +0100 |
---|---|---|
committer | Andy Shaw <andy.shaw@qt.io> | 2019-11-15 15:08:31 +0100 |
commit | a425dd954b4319455fc29372ff2314e7dc81ee77 (patch) | |
tree | 62794bc953c06302cbc0de1ad39a6b9d8127e1e6 | |
parent | 664a83674b2bf8313763870c9eca7c4c558a14bc (diff) | |
download | qtlocation-a425dd954b4319455fc29372ff2314e7dc81ee77.tar.gz |
Re-request authorization after the authorization has changed
On iOS if an application is put into the background after it was
authorized to allow location updates "Only Once" then when it is brought
back it is no longer getting updates. Therefore we need to rerequest the
authorization so that it can continue to get updates.
Change-Id: I72804a7c7e82524e40aab049175e2d8f7dfee469
Reviewed-by: Paolo Angelelli <paolo.angelelli@qt.io>
-rw-r--r-- | src/plugins/position/corelocation/qgeopositioninfosource_cl.mm | 25 |
1 files changed, 15 insertions, 10 deletions
diff --git a/src/plugins/position/corelocation/qgeopositioninfosource_cl.mm b/src/plugins/position/corelocation/qgeopositioninfosource_cl.mm index fae16715..2d412138 100644 --- a/src/plugins/position/corelocation/qgeopositioninfosource_cl.mm +++ b/src/plugins/position/corelocation/qgeopositioninfosource_cl.mm @@ -61,6 +61,12 @@ } return self; } +- (void)locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status +{ + Q_UNUSED(manager) + if (status == kCLAuthorizationStatusNotDetermined) + m_positionInfoSource->requestUpdate(MINIMUM_UPDATE_INTERVAL); +} - (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation { @@ -198,22 +204,21 @@ bool QGeoPositionInfoSourceCL::enableLocationManager() // 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"]; + NSDictionary<NSString *, id> *infoDict = NSBundle.mainBundle.infoDictionary; + const bool hasAlwaysUseUsage = !![infoDict objectForKey:@"NSLocationAlwaysAndWhenInUseUsageDescription"]; + const bool hasWhenInUseUsage = !![infoDict objectForKey:@"NSLocationWhenInUseUsageDescription"]; #ifndef Q_OS_TVOS - if (hasAlwaysUseUsage && hasWhenInUseUsage) - [m_locationManager requestAlwaysAuthorization]; - else + if (hasAlwaysUseUsage && hasWhenInUseUsage) + [m_locationManager requestAlwaysAuthorization]; + else #endif // !Q_OS_TVOS - if (hasWhenInUseUsage) - [m_locationManager requestWhenInUseAuthorization]; + if (hasWhenInUseUsage) + [m_locationManager requestWhenInUseAuthorization]; #endif // !Q_OS_MACOS - } - return (m_locationManager != nullptr); } |