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

Change-Id: Id006dbbb2f6fad4b831742e4d3e904525aaa8a2a
Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io>
(cherry picked from commit 8dc3ee03a42ccb1b047c2a8f34b5bce4e663c9d9)
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
This commit is contained in:
Tor Arne Vestbø 2023-02-02 13:02:03 +01:00 committed by Qt Cherry-pick Bot
parent ac0238478a
commit b99f9c50c0

View File

@ -83,10 +83,9 @@ struct PermissionRequest
return Qt::PermissionStatus::Granted;
#ifdef Q_OS_IOS
case kCLAuthorizationStatusAuthorizedWhenInUse:
if (permission.availability() == QLocationPermission::WhenInUse)
if (permission.availability() == QLocationPermission::Always)
return Qt::PermissionStatus::Denied;
return Qt::PermissionStatus::Granted;
else
return Qt::PermissionStatus::Denied; // FIXME: Verify
#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];
}