fix(macos): resolve deprecated authorizationStatus warnings in geolocator_apple#1773
Open
Tinnci wants to merge 3 commits intoBaseflow:mainfrom
Open
fix(macos): resolve deprecated authorizationStatus warnings in geolocator_apple#1773Tinnci wants to merge 3 commits intoBaseflow:mainfrom
Tinnci wants to merge 3 commits intoBaseflow:mainfrom
Conversation
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 Baseflow#1732
There was a problem hiding this comment.
Pull request overview
Updates the iOS/macOS permission handling in geolocator_apple to use the iOS 14+/macOS 11+ instance-based authorization status API and to silence deprecation warnings when falling back to the legacy class method.
Changes:
- Wraps the legacy
[CLLocationManager authorizationStatus]call with clang diagnostic pragmas to suppress deprecation warnings. - Updates
requestPermissionto use the sharedcheckPermissionhelper for determining current authorization status.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
geolocator_apple/darwin/geolocator_apple/Sources/geolocator_apple/Handlers/PermissionHandler.m
Outdated
Show resolved
Hide resolved
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.
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes deprecated
CLLocationManager.authorizationStatuswarnings on macOS 11+ builds ingeolocator_apple.Problem
When building for macOS, Xcode emits deprecation warnings:
There are two call sites in
PermissionHandler.m:checkPermission(line ~42): Theelsebranch of an@available(iOS 14, macOS 11, *)check calls the deprecated class method[CLLocationManager authorizationStatus]. This is correct behavior for older OS versions but triggers a warning on modern SDKs.requestPermission:errorHandler:(line ~53): UsesCLLocationManager.authorizationStatuswithout any@availableguard.See #1732.
Solution
checkPermission: Wrap the deprecated call in#pragma clang diagnostic push/ignored/popto suppress the warning in theelsebranch, since we already know we're on an older OS version at that point.requestPermission:errorHandler:: Replace the unguardedCLLocationManager.authorizationStatuswith[self checkPermission], which already has the proper@availableguard and returns the sameCLAuthorizationStatusvalue.Testing
PermissionHandler.mCloses #1732