iOS: Disallow upgrading QLocationPermission::WhenInUse to Always

This is technically possible on iOS, but the system doesn't give us
a callback unless the user accepts the upgraded permission level,
and we need a deterministic callback in both cases so that we can
report the result back to the permission request callback.

  https://tinyurl.com/requestalwaysauthorization

Pick-to: 6.5
Change-Id: Id006dbbb2f6fad4b831742e4d3e904525aaa8a2a
Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io>
bb10
Tor Arne Vestbø 2023-02-02 13:02:03 +01:00
parent e2030e366b
commit 8dc3ee03a4
1 changed files with 15 additions and 7 deletions

View File

@ -83,10 +83,9 @@ struct PermissionRequest
return Qt::PermissionStatus::Granted;
#ifdef Q_OS_IOS
case kCLAuthorizationStatusAuthorizedWhenInUse:
if (permission.availability() == QLocationPermission::WhenInUse)
return Qt::PermissionStatus::Granted;
else
return Qt::PermissionStatus::Denied; // FIXME: Verify
if (permission.availability() == QLocationPermission::Always)
return Qt::PermissionStatus::Denied;
return Qt::PermissionStatus::Granted;
#endif
}
@ -176,11 +175,20 @@ struct PermissionRequest
// or authorized when in use.
switch ([self authorizationStatus]) {
case kCLAuthorizationStatusNotDetermined:
#ifdef Q_OS_IOS
case kCLAuthorizationStatusAuthorizedWhenInUse:
#endif
[self.manager requestAlwaysAuthorization];
break;
#ifdef Q_OS_IOS
case kCLAuthorizationStatusAuthorizedWhenInUse:
// Unfortunately when asking for AlwaysAuthorization when in
// the WhenInUse state, to "upgrade" the permission, the iOS
// location system will not give us a callback if the user
// denies the request, leaving us hanging without a way to
// respond to the permission request.
qCWarning(lcLocationPermission) << "QLocationPermission::WhenInUse"
<< "can not be upgraded to QLocationPermission::Always on iOS."
<< "Please request QLocationPermission::Always directly.";
Q_FALLTHROUGH();
#endif
default:
[self deliverResult];
}