diff --git a/geolocator_apple/CHANGELOG.md b/geolocator_apple/CHANGELOG.md index 672503ecc..677656279 100644 --- a/geolocator_apple/CHANGELOG.md +++ b/geolocator_apple/CHANGELOG.md @@ -1,3 +1,7 @@ +## 2.3.14 + +* Deprecation warning fixes and updates. + ## 2.3.13 * Adds Swift Package Manager compatibility. 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..49f8b2063 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,17 +33,40 @@ - (FlutterError * _Nullable)onListenWithArguments:(id _Nullable)arguments eventS return nil; } -- (void)locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status{ - dispatch_async(dispatch_get_global_queue( DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ - BOOL isEnabled = [CLLocationManager locationServicesEnabled]; - dispatch_async(dispatch_get_main_queue(), ^(void) { - if (isEnabled) { - self->_eventSink([NSNumber numberWithInt:(ServiceStatus)enabled]); - } else { - self->_eventSink([NSNumber numberWithInt:(ServiceStatus)disabled]); - } +#pragma location authorization delegates fror older and newer versions + +// for implementations of macOS 11+ en iOS 14+ +- (void)locationManagerDidChangeAuthorization:(CLLocationManager *)manager { +#if TARGET_OS_OSX || __IPHONE_OS_VERSION_MAX_ALLOWED >= 140000 + if (@available(iOS 14.0, *)) { + CLAuthorizationStatus status = manager.authorizationStatus; + [self handleAuthorizationStatus:status]; + } else { + // Not possible + } +#endif +} + +// older versions (iOS < 14, macOS < 11) +- (void)locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status { + [self handleAuthorizationStatus:status]; +} + +- (void)handleAuthorizationStatus:(CLAuthorizationStatus)status { + dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ + BOOL isEnabled = [CLLocationManager locationServicesEnabled]; + dispatch_async(dispatch_get_main_queue(), ^{ + if (isEnabled) { + if (self->_eventSink) { + self->_eventSink(@(enabled)); + } + } else { + if (self->_eventSink) { + self->_eventSink(@(disabled)); + } + } + }); }); - }); } @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 265401aad..e84e05acc 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,18 @@ - (CLAuthorizationStatus) checkPermission { if (@available(iOS 14, macOS 11, *)) { return [self.getLocationManager authorizationStatus]; } else { + // Needed to get rid of the deprection warnings. It is handled properly, however, we need to inform the compiler that this is required for backwards competability. + #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; @@ -104,16 +108,36 @@ - (BOOL) containsLocationAlwaysDescription { } #endif -- (void) locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status { - if (status == kCLAuthorizationStatusNotDetermined) { - return; - } - - if (self.confirmationHandler) { - self.confirmationHandler(status); - } - - [self cleanUp]; +#pragma location authorization delegates fror older and newer versions + +// Newer versions +- (void)locationManagerDidChangeAuthorization:(CLLocationManager *)manager { +#if TARGET_OS_OSX || __IPHONE_OS_VERSION_MAX_ALLOWED >= 140000 + if (@available(iOS 14.0, *)) { + CLAuthorizationStatus status = manager.authorizationStatus; + [self handleAuthorizationStatus:status]; + } else { + // Not possile + } +#endif +} + +// Olders verions +- (void)locationManager:(CLLocationManager *)manager didChangeAuthorization:(CLAuthorizationStatus)status { + [self handleAuthorizationStatus:status]; +} + +// Shared handler +- (void)handleAuthorizationStatus:(CLAuthorizationStatus)status { + if (status == kCLAuthorizationStatusNotDetermined) { + return; + } + + if (self.confirmationHandler) { + self.confirmationHandler(status); + } + + [self cleanUp]; } - (void) cleanUp { diff --git a/geolocator_apple/example/ios/Runner.xcodeproj/project.pbxproj b/geolocator_apple/example/ios/Runner.xcodeproj/project.pbxproj index f203a58ed..ce3e1ecc4 100644 --- a/geolocator_apple/example/ios/Runner.xcodeproj/project.pbxproj +++ b/geolocator_apple/example/ios/Runner.xcodeproj/project.pbxproj @@ -194,6 +194,7 @@ 97C146EC1CF9000F007C117D /* Resources */, 9705A1C41CF9048500538489 /* Embed Frameworks */, 3B06AD1E1E4923F5004D2608 /* Thin Binary */, + C98A7D11CFBC621F785971D0 /* [CP] Copy Pods Resources */, ); buildRules = ( ); @@ -232,6 +233,7 @@ 97C146E61CF9000F007C117D /* Project object */ = { isa = PBXProject; attributes = { + BuildIndependentTargetsInParallel = YES; LastUpgradeCheck = 1510; ORGANIZATIONNAME = ""; TargetAttributes = { @@ -363,6 +365,23 @@ shellPath = /bin/sh; shellScript = "/bin/sh \"$FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend.sh\" build"; }; + C98A7D11CFBC621F785971D0 /* [CP] Copy Pods Resources */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputFileListPaths = ( + "${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-resources-${CONFIGURATION}-input-files.xcfilelist", + ); + name = "[CP] Copy Pods Resources"; + outputFileListPaths = ( + "${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-resources-${CONFIGURATION}-output-files.xcfilelist", + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-resources.sh\"\n"; + showEnvVarsInLog = 0; + }; /* End PBXShellScriptBuildPhase section */ /* Begin PBXSourcesBuildPhase section */ @@ -438,6 +457,7 @@ CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; CLANG_WARN_STRICT_PROTOTYPES = YES; CLANG_WARN_SUSPICIOUS_MOVE = YES; @@ -448,6 +468,7 @@ DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; ENABLE_NS_ASSERTIONS = NO; ENABLE_STRICT_OBJC_MSGSEND = YES; + ENABLE_USER_SCRIPT_SANDBOXING = NO; GCC_C_LANGUAGE_STANDARD = gnu99; GCC_NO_COMMON_BLOCKS = YES; GCC_WARN_64_TO_32_BIT_CONVERSION = YES; @@ -514,6 +535,7 @@ CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; CLANG_WARN_STRICT_PROTOTYPES = YES; CLANG_WARN_SUSPICIOUS_MOVE = YES; @@ -524,6 +546,7 @@ DEBUG_INFORMATION_FORMAT = dwarf; ENABLE_STRICT_OBJC_MSGSEND = YES; ENABLE_TESTABILITY = YES; + ENABLE_USER_SCRIPT_SANDBOXING = NO; GCC_C_LANGUAGE_STANDARD = gnu99; GCC_DYNAMIC_NO_PIC = NO; GCC_NO_COMMON_BLOCKS = YES; @@ -569,6 +592,7 @@ CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; CLANG_WARN_STRICT_PROTOTYPES = YES; CLANG_WARN_SUSPICIOUS_MOVE = YES; @@ -579,6 +603,7 @@ DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; ENABLE_NS_ASSERTIONS = NO; ENABLE_STRICT_OBJC_MSGSEND = YES; + ENABLE_USER_SCRIPT_SANDBOXING = NO; GCC_C_LANGUAGE_STANDARD = gnu99; GCC_NO_COMMON_BLOCKS = YES; GCC_WARN_64_TO_32_BIT_CONVERSION = YES; diff --git a/geolocator_apple/example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme b/geolocator_apple/example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme index c90b55d4f..82e7ec1e8 100644 --- a/geolocator_apple/example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme +++ b/geolocator_apple/example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme @@ -1,7 +1,7 @@ + version = "1.7"> @@ -44,6 +44,7 @@ buildConfiguration = "Debug" selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" + customLLDBInitFile = "$(SRCROOT)/Flutter/ephemeral/flutter_lldbinit" shouldUseLaunchSchemeArgsEnv = "YES">