From b5acf0f28a0755cf3e5d56614a39446289ccace7 Mon Sep 17 00:00:00 2001 From: driezy Date: Thu, 12 Mar 2026 11:32:25 +0800 Subject: [PATCH 1/3] fix(macos): resolve deprecated authorizationStatus warnings 1. checkPermission: suppress deprecation warning in else-branch with #pragma clang diagnostic, since CLLocationManager.authorizationStatus (class method) is only called on iOS < 14 / macOS < 11. 2. requestPermission: replace unguarded CLLocationManager.authorizationStatus with [self checkPermission] which already has the @available guard. Closes #1732 --- .../Sources/geolocator_apple/Handlers/PermissionHandler.m | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/geolocator_apple/darwin/geolocator_apple/Sources/geolocator_apple/Handlers/PermissionHandler.m b/geolocator_apple/darwin/geolocator_apple/Sources/geolocator_apple/Handlers/PermissionHandler.m index 265401aad..972350a3d 100644 --- a/geolocator_apple/darwin/geolocator_apple/Sources/geolocator_apple/Handlers/PermissionHandler.m +++ b/geolocator_apple/darwin/geolocator_apple/Sources/geolocator_apple/Handlers/PermissionHandler.m @@ -37,14 +37,17 @@ - (CLAuthorizationStatus) checkPermission { if (@available(iOS 14, macOS 11, *)) { return [self.getLocationManager authorizationStatus]; } else { +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wdeprecated-declarations" return [CLLocationManager authorizationStatus]; +#pragma clang diagnostic pop } } - (void) requestPermission:(PermissionConfirmation)confirmationHandler errorHandler:(PermissionError)errorHandler { // When we already have permission we don't have to request it again - CLAuthorizationStatus authorizationStatus = CLLocationManager.authorizationStatus; + CLAuthorizationStatus authorizationStatus = [self checkPermission]; if (authorizationStatus != kCLAuthorizationStatusNotDetermined) { confirmationHandler(authorizationStatus); return; From 1254b3c3da58372e3ad775e270ebb453ac983b29 Mon Sep 17 00:00:00 2001 From: driezy Date: Thu, 12 Mar 2026 11:47:06 +0800 Subject: [PATCH 2/3] fix(macos): replace deprecated didChangeAuthorizationStatus delegate Add the new locationManagerDidChangeAuthorization: delegate method (available iOS 14+ / macOS 11+) to both PermissionHandler and LocationServiceStreamHandler. Keep the old didChangeAuthorizationStatus: method for backward compatibility with iOS < 14 / macOS < 11, suppressing the -Wdeprecated-implementations warning with #pragma. Extract _notifyServiceStatus helper in LocationServiceStreamHandler to avoid duplicating the dispatch logic. --- .../Handlers/LocationServiceStreamHandler.m | 15 ++++++++++++++- .../Handlers/PermissionHandler.m | 18 ++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/geolocator_apple/darwin/geolocator_apple/Sources/geolocator_apple/Handlers/LocationServiceStreamHandler.m b/geolocator_apple/darwin/geolocator_apple/Sources/geolocator_apple/Handlers/LocationServiceStreamHandler.m index e1da68293..01492a792 100644 --- a/geolocator_apple/darwin/geolocator_apple/Sources/geolocator_apple/Handlers/LocationServiceStreamHandler.m +++ b/geolocator_apple/darwin/geolocator_apple/Sources/geolocator_apple/Handlers/LocationServiceStreamHandler.m @@ -33,7 +33,7 @@ - (FlutterError * _Nullable)onListenWithArguments:(id _Nullable)arguments eventS return nil; } -- (void)locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status{ +- (void)_notifyServiceStatus { dispatch_async(dispatch_get_global_queue( DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ BOOL isEnabled = [CLLocationManager locationServicesEnabled]; dispatch_async(dispatch_get_main_queue(), ^(void) { @@ -46,4 +46,17 @@ - (void)locationManager:(CLLocationManager *)manager didChangeAuthorizationStatu }); } +// iOS 14+ / macOS 11+: preferred delegate callback +- (void)locationManagerDidChangeAuthorization:(CLLocationManager *)manager { + [self _notifyServiceStatus]; +} + +// Fallback for iOS < 14 / macOS < 11 +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wdeprecated-implementations" +- (void)locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status{ + [self _notifyServiceStatus]; +} +#pragma clang diagnostic pop + @end diff --git a/geolocator_apple/darwin/geolocator_apple/Sources/geolocator_apple/Handlers/PermissionHandler.m b/geolocator_apple/darwin/geolocator_apple/Sources/geolocator_apple/Handlers/PermissionHandler.m index 972350a3d..2b5ad7b19 100644 --- a/geolocator_apple/darwin/geolocator_apple/Sources/geolocator_apple/Handlers/PermissionHandler.m +++ b/geolocator_apple/darwin/geolocator_apple/Sources/geolocator_apple/Handlers/PermissionHandler.m @@ -107,6 +107,23 @@ - (BOOL) containsLocationAlwaysDescription { } #endif +// iOS 14+ / macOS 11+: preferred delegate callback +- (void) locationManagerDidChangeAuthorization:(CLLocationManager *)manager { + CLAuthorizationStatus status = [self checkPermission]; + if (status == kCLAuthorizationStatusNotDetermined) { + return; + } + + if (self.confirmationHandler) { + self.confirmationHandler(status); + } + + [self cleanUp]; +} + +// Fallback for iOS < 14 / macOS < 11 +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wdeprecated-implementations" - (void) locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status { if (status == kCLAuthorizationStatusNotDetermined) { return; @@ -118,6 +135,7 @@ - (void) locationManager:(CLLocationManager *)manager didChangeAuthorizationStat [self cleanUp]; } +#pragma clang diagnostic pop - (void) cleanUp { self.locationManager = nil; From 935f6c805e4ea31af9b4d8f1438e3cfab3207af0 Mon Sep 17 00:00:00 2001 From: driezy Date: Thu, 12 Mar 2026 11:51:34 +0800 Subject: [PATCH 3/3] fix: avoid unnecessary CLLocationManager allocation on early-return path Restore the direct class method call CLLocationManager.authorizationStatus with #pragma suppression in requestPermission, so the early-return path does not trigger getLocationManager to lazily create and retain a manager. Address Copilot review comment on lines 49-51. --- .../geolocator_apple/Handlers/PermissionHandler.m | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/geolocator_apple/darwin/geolocator_apple/Sources/geolocator_apple/Handlers/PermissionHandler.m b/geolocator_apple/darwin/geolocator_apple/Sources/geolocator_apple/Handlers/PermissionHandler.m index 2b5ad7b19..cbcfea207 100644 --- a/geolocator_apple/darwin/geolocator_apple/Sources/geolocator_apple/Handlers/PermissionHandler.m +++ b/geolocator_apple/darwin/geolocator_apple/Sources/geolocator_apple/Handlers/PermissionHandler.m @@ -46,8 +46,13 @@ - (CLAuthorizationStatus) checkPermission { - (void) requestPermission:(PermissionConfirmation)confirmationHandler errorHandler:(PermissionError)errorHandler { - // When we already have permission we don't have to request it again - CLAuthorizationStatus authorizationStatus = [self checkPermission]; + // When we already have permission we don't have to request it again. + // Use the class method directly (with warning suppression) to avoid + // lazily creating and retaining a CLLocationManager on the early-return path. +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wdeprecated-declarations" + CLAuthorizationStatus authorizationStatus = CLLocationManager.authorizationStatus; +#pragma clang diagnostic pop if (authorizationStatus != kCLAuthorizationStatusNotDetermined) { confirmationHandler(authorizationStatus); return;