flutterlocation icon indicating copy to clipboard operation
flutterlocation copied to clipboard

[iOS] "getLocation" not resolving

Open maerlynflagg opened this issue 3 years ago • 24 comments

Describe the bug a show a waiter around the function getLocation(). so a customer found out, the waiter is not hiding. the reason is, that the line await _locationPlugin.getLocation() is not resolving.

after testing and debugging i found out, that the function ist not resolving, if the user clicked "Allow once". i can reproduce it with an simulator, if i clicking "Allow once".

Expected behavior getLocation should be resolving or thrown a error.

Tested on:

  • customer iOS device
  • iOS iPad Air 2
  • iOS Si

Additional logs in Visual Studio Code or in XCode i saw no errors.

EDIT

Flutter 2.2.3
location: ^4.3.0

EDIT

the devices , where we tested this behavior are real devices, but on simulator i get this issue too.

maerlynflagg avatar Aug 17 '21 13:08 maerlynflagg

Same issue, its stuck...when i restart app it resolve it and continue...every second run of app works!!!

radvansky-tomas avatar Aug 27 '21 07:08 radvansky-tomas

Same Issue, happens only on IOS

oselesley avatar Aug 27 '21 17:08 oselesley

Same Issue, happens only on IOS

cmorsucci avatar Aug 28 '21 08:08 cmorsucci

I'm also experiencing the exact same thing, function not resolving on the first run. We need to restart the app to go through getLocation()

jpcarreira avatar Aug 28 '21 09:08 jpcarreira

Was anyone able to solve this ? I am currently facing the same issue. Android works fine its just IOS, even if I restart the app on the simulator it still doesn't ask for permissions. Are there any workarounds for this bug ?

Faisalkc4u avatar Aug 31 '21 11:08 Faisalkc4u

I have the same issue.

However, I tried creating a simple example for demonstration and could not replicate this. So perhaps we're doing something wrong?

This is the dummy example I have created: location.zip

ademanuele avatar Sep 01 '21 15:09 ademanuele

Correction: I can replicate it when giving the simulator a single custom location which doesn't change.

In this case, the first call to getLocation() returns, however another call does not return and gets stuck.

If you set the simulator's location to "City Run" however, this is not reproducable. So it seems that this only happens when the location is fixed and unchanging.

ademanuele avatar Sep 02 '21 06:09 ademanuele

Was anyone able to solve this ? I am currently facing the same issue. Android works fine its just IOS, even if I restart the app on the simulator it still doesn't ask for permissions. Are there any workarounds for this bug ?

the only workaround what i know do, is to timeout the promise, so that the App not freeze and waits for getLocation().

maerlynflagg avatar Sep 02 '21 07:09 maerlynflagg

@Lyokone Could you review the merge request soon please? This is a huge issue for our app. Thanks!

LostInDarkMath avatar Sep 17 '21 18:09 LostInDarkMath

I experienced this only on iOS simulator. Hope the merge request is reviewed soon.

martesabt avatar Sep 27 '21 09:09 martesabt

Maybe requesting the location a second time is valid workaround for this. The first, the Future of getLocation() does not return, but the second time it does.

So instead of

LocationData location = await _locator.getLocation();

use this:

    LocationData? location;
    while(location == null) {
      try {
        location = await Future.any<LocationData>([
          _locator.getLocation(), // we hope this returns first
          Future.delayed(const Duration(seconds: 5), () => throw LocatorTimeout()),
        ]);
      } on LocatorTimeout {
        print('LocatorTimeout. Trying again...');
      }
    }

Does this work for you?

LostInDarkMath avatar Sep 30 '21 19:09 LostInDarkMath

@Lyokone Could you review the merge request soon please? This is a huge issue for our app. Thanks!

I tested out that commit on my app but the issue still persists.

see implementation below

     git:
      url: https://github.com/ademanuele/flutterlocation.git
      path: packages/location
      ref: 6810b7e338173ff26a0a52a25721060a563e625f   ```

wiseminds avatar Sep 30 '21 19:09 wiseminds

Hi @wiseminds.

Do you mean you tried the code in this MR and it did not work for you? Could you describe any change in the behaviour if you notice any please?

ademanuele avatar Oct 05 '21 15:10 ademanuele

There was no difference. I still couldn’t get location.

wiseminds avatar Oct 05 '21 15:10 wiseminds

Maybe requesting the location a second time is valid workaround for this. The first, the Future of getLocation() does not return, but the second time it does.

So instead of

LocationData location = await _locator.getLocation();

use this:

    LocationData? location;
    while(location == null) {
      try {
        location = await Future.any<LocationData>([
          _locator.getLocation(), // we hope this returns first
          Future.delayed(const Duration(seconds: 5), () => throw LocatorTimeout()),
        ]);
      } on LocatorTimeout {
        print('LocatorTimeout. Trying again...');
      }
    }

Does this work for you?

Actually the problem is that it doesn't work after first call. So it doesn't matter how many times you try...

AlpSha avatar Oct 15 '21 22:10 AlpSha

@AlpSha Yes, I think you are right. The problem seems to different on different platforms. I had this problem on bith Android and iOS. On Android, the second call is successful so my workwaround fixes the issue on Android. But on iOS it looks like this is not the case. Did you test on Android or iOS?

LostInDarkMath avatar Oct 16 '21 06:10 LostInDarkMath

@LostInDarkMath Tested on both. Android works fine without any workaround but iOS has the issue.

AlpSha avatar Oct 16 '21 08:10 AlpSha

Hi,

I had the same issue on iOS Simulator. I've just noticed that the issue only occured when the simulator location settings (Features, Location) were set to Custom Location.... Any other setting it seemed to work fine. Might help?

RedHappyLlama avatar Nov 05 '21 12:11 RedHappyLlama

Hi, i have the same issue, do you have any idea how can i fix-it please ?

ibraah88 avatar Nov 13 '21 20:11 ibraah88

Same issue any update ?

anirudhsharma392 avatar Feb 02 '22 16:02 anirudhsharma392

return await _location.getLocation().timeout(Duration(seconds: 5));

dvird avatar Feb 17 '22 01:02 dvird

Now in Android the issue is pressent.

neoacevedo avatar Mar 30 '22 17:03 neoacevedo

The problem persists for iOS.

m2sahin avatar Jul 04 '22 14:07 m2sahin

this week icg noticed that getLocation still doesn't work in the iOS simulator.

the app keeps waiting for a result to come back or at least an error to be thrown.

maerlynflagg avatar Nov 22 '22 20:11 maerlynflagg