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

[Question]: getCurrentPosition not working on iOS Testflight

Open ariefsn opened this issue 1 year ago • 4 comments

Please check the following before submitting a new issue.

Please select for which platform(s) you need help

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

Your question

Hi, I have a problem after uploading to TestFlight. Popup permission shown, already granted. But it is stuck at getCurrentPosition never returns.

Android:

  • Real device ✅

iOS:

  • Debug with Simulator ✅
  • Debug with Real Device ✅
  • TestFlight ⛔️

Added these to Info.plist

NSLocationAlwaysUsageDescription
NSLocationWhenInUseUsageDescription
NSLocationAlwaysAndWhenInUseUsageDescription
// geolocation.dart
import 'package:geolocator/geolocator.dart';

/// Determine the current position of the device.
///
/// When the location services are not enabled or permissions
/// are denied the `Future` will return an error.
Future<Position> getMyLocation() async {
  bool serviceEnabled;
  LocationPermission permission;

  // Test if location services are enabled.
  serviceEnabled = await Geolocator.isLocationServiceEnabled();
  if (!serviceEnabled) {
    // Location services are not enabled don't continue
    // accessing the position and request users of the
    // App to enable the location services.
    await Geolocator.openLocationSettings();
    return Future.error('Location services are disabled.');
  }

  permission = await Geolocator.checkPermission();
  if (permission == LocationPermission.denied) {
    permission = await Geolocator.requestPermission();
    if (permission == LocationPermission.denied) {
      // Permissions are denied, next time you could try
      // requesting permissions again (this is also where
      // Android's shouldShowRequestPermissionRationale
      // returned true. According to Android guidelines
      // your App should show an explanatory UI now.
      return Future.error('Location permissions are denied');
    }
  }

  if (permission == LocationPermission.deniedForever) {
    // Permissions are denied forever, handle appropriately.
    return Future.error(
        'Location permissions are permanently denied, we cannot request permissions.');
  }

  // When we reach here, permissions are granted and we can
  // continue accessing the position of the device.
  final pos = await Geolocator.getCurrentPosition(
    timeLimit: const Duration(minutes: 1),
    forceAndroidLocationManager: false,
  );
  return pos;
}

XCode: 15.3 Flutter: 3.22.1 Geolocator: 12.0.0 Device: iOS 17.4.1

Thanks 🙏🏻

Version

12.0.0

ariefsn avatar May 28 '24 11:05 ariefsn

Dear @ariefsn,

Is the TestFlight build installed on the same device as the "Real" de device build? And can you remove the installed version entirely on the device before installing the "TestFlight build"? And can you test your app on a local device running in "Release" flutter run --release mode? For any possible changes?

Kind regards,

Tim

TimHoogstrate avatar May 31 '24 09:05 TimHoogstrate

Dear @ariefsn,

Is the TestFlight build installed on the same device as the "Real" de device build? And can you remove the installed version entirely on the device before installing the "TestFlight build"? And can you test your app on a local device running in "Release" flutter run --release mode? For any possible changes?

Kind regards,

Tim

Yes, it's the same device. Already did that, remove first, then re-install from TestFlight, still same. Run release mode working fine 🙁

ariefsn avatar May 31 '24 22:05 ariefsn

Hi We have the same problem here, when the location of the simulator is set to none, the splash screen keeps freezing. When I set the location to custom location it continues. With my test I have found that the code stops after getCurrentPosition() when Location is set to None (it doens't return anything and just wait). It is not possible to grab in catch.

ramaces avatar Jun 03 '24 07:06 ramaces

use TimeLimit 5 seconds

ramaces avatar Jun 03 '24 08:06 ramaces

Dear @ramaces,

Thanks for you input could you file a separate issue? Locations testing on simulators could lead to strange behaviour. It is advised to test on a real device.

Kind regards,

Tim

TimHoogstrate avatar Jul 01 '24 09:07 TimHoogstrate

Same issue Have you fixed it yet? @ariefsn

WanTranAndroid avatar Aug 04 '24 03:08 WanTranAndroid

Same issue

Have you fixed it yet? @ariefsn

Yea it's fixed, but I don't know which step that resolved that 🫣 Here are steps that I tried, you can try.

  • Upgrade flutter to latest
  • Clear XCode cache
  • Clean and reinstall deps
  • Rebuild and reupload to Testflight

ariefsn avatar Aug 04 '24 07:08 ariefsn

Same issue Have you fixed it yet? @ariefsn

Yea it's fixed, but I don't know which step that resolved that 🫣 Here are steps that I tried, you can try.

  • Upgrade flutter to latest
  • Clear XCode cache
  • Clean and reinstall deps
  • Rebuild and reupload to Testflight

Can u share code for me

WanTranAndroid avatar Aug 04 '24 14:08 WanTranAndroid

use timeout and it will be work on simulator also

ramaces avatar Aug 04 '24 21:08 ramaces

It looks like this issue has been resolved.

I'll close this issue for now. Feel free to reopen or file a new issue with additional information.

Kind regards,

TimHoogstrate avatar Aug 05 '24 06:08 TimHoogstrate