From b99f9c50c04dfaa6d4d8ecc802ca61e23e4c1fe5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Thu, 2 Feb 2023 13:02:03 +0100 Subject: [PATCH] iOS: Disallow upgrading QLocationPermission::WhenInUse to Always MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 (cherry picked from commit 8dc3ee03a42ccb1b047c2a8f34b5bce4e663c9d9) Reviewed-by: Tor Arne Vestbø --- .../qdarwinpermissionplugin_location.mm | 22 +++++++++++++------ 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/src/corelib/platform/darwin/qdarwinpermissionplugin_location.mm b/src/corelib/platform/darwin/qdarwinpermissionplugin_location.mm index c355a74b7cd..c6cbebe5388 100644 --- a/src/corelib/platform/darwin/qdarwinpermissionplugin_location.mm +++ b/src/corelib/platform/darwin/qdarwinpermissionplugin_location.mm @@ -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]; }