Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,22 @@ - (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
// 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;
Expand Down Expand Up @@ -104,6 +112,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;
Expand All @@ -115,6 +140,7 @@ - (void) locationManager:(CLLocationManager *)manager didChangeAuthorizationStat

[self cleanUp];
}
#pragma clang diagnostic pop

- (void) cleanUp {
self.locationManager = nil;
Expand Down
Loading