flutter-geolocator icon indicating copy to clipboard operation
flutter-geolocator copied to clipboard

[Bug]: LocationServices.getPosition, kCLErrorDomain error 1

Open prasad-rawas-volofleet opened this issue 1 year ago • 0 comments

Please select affected platform(s)

  • [ ] Android
  • [X] iOS
  • [ ] Linux
  • [ ] macOS
  • [ ] Web
  • [ ] Windows

Issue:

The reason behind this crash is when the app has all the required location permissions ready to fetch the current location, but the device's GPS, Wi-Fi, or network cannot fetch the location. This is where the crash occurs.

One thing to notice here is that this crash only appears when we put the app in the background. This seems like a library issue that attempts to fetch the location when the app enters the background. This shouldn't happen as I did not configure any iOS native settings (info.plist) to fetch the location in the background.

However, reproducing this issue on a real iPhone is very difficult because fetching GPS location rarely fails. It might only occur when the user's device is in a closed room where it does not have access to networks or Wi-Fi. Reference: https://stackoverflow.com/a/30527673

I was able to reproduce this issue only in the iOS simulator, where we can manually set the location to None: (Features -> Locations -> None).

Steps to reproduce

  • Allow the app permission to access the location.
  • Ensure that the location setting is turned on in your system.
  • Make sure you are in a location where the device's GPS will not work, or use the iOS simulator and set the location to None.
  • Put the app in the background and wait for 20 seconds for the crash to occur.

Expected results

  • Should not try to fetch location when app goes to background.
  • Should not throw any exception.

Actual results

  • Throws Exception: LocationServices.getPosition, kCLErrorDomain error 1

Code sample

Code sample
try {
        final location = await Geolocator.getCurrentPosition();
        return location;
      } catch (e) {
        print('Exception:: $e');
      }

Screenshots or video

Screenshots or video demonstration

[Upload media here]

Version

3.16.9

Flutter Doctor output

Doctor output
[✓] Flutter (Channel stable, 3.16.9, on macOS 14.2.1 23C71 darwin-x64, locale
    en-US)
    • Flutter version 3.16.9 on channel stable at
      /Users/Developer/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 41456452f2 (7 days ago), 2024-01-25 10:06:23 -0800
    • Engine revision f40e976bed
    • Dart version 3.2.6
    • DevTools version 2.28.5

[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
    • Android SDK at /Users/Library/Android/sdk
    • Platform android-34, build-tools 34.0.0
    • ANDROID_HOME = /Users/Library/Android/sdk
    • Java binary at: /Applications/Android
      Studio.app/Contents/jbr/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build
      17.0.7+0-17.0.7b1000.6-10550314)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 15.0.1)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 15A507
    • CocoaPods version 1.14.3

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2023.1)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build
      17.0.7+0-17.0.7b1000.6-10550314)

[✓] IntelliJ IDEA Ultimate Edition (version 2023.3.3)
    • IntelliJ at /Applications/IntelliJ IDEA.app
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart

[✓] VS Code (version 1.85.2)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.80.0

[✓] Connected device (4 available)
    • iPhone (mobile)                      • ios            • iOS 17.2.1 21C66
    • iPhone 14 Pro Max (mobile)  • ios            •
      com.apple.CoreSimulator.SimRuntime.iOS-17-0 (simulator)
    • macOS (desktop)            • macos                                • darwin-x64     • macOS 14.2.1 23C71 darwin-x64
    • Chrome (web)               • chrome                               • web-javascript • Google Chrome 121.0.6167.85

[✓] Network resources
    • All expected network resources are available.

• No issues found!

prasad-rawas-volofleet avatar Feb 01 '24 13:02 prasad-rawas-volofleet