Flutter-geolocator: getCurrentPosition close app [iOS]

Created on 19 Aug 2020  路  6Comments  路  Source: Baseflow/flutter-geolocator

馃悰 Bug Report

When i use getCurrentPosition the app closes,

Version: 5.3.2+2

Platform:

  • [X] :iphone: iOS
  • [ ] :robot: Android
ios bug

Most helpful comment

@samo92, @vijayanbits during the weekend I published a release candidate for version 6.0.0 on pub.dev which solves a lot of problems specifically with permissions and reporting if the location services are not enabled.

I would very much appreciate it if you can give it a try and see if it solves this problem. Hope to hear from you.

All 6 comments

Have you added the required configuration to your ios/Runner/Info.plist file (see the Permission section in the README.md)?

Hello there, my info.plist has:

NSLocationWhenInUseUsageDescription
This app needs access to location when open.
NSLocationAlwaysUsageDescription
This app needs access to location when in the background.
NSLocationAlwaysAndWhenInUseUsageDescription
This app needs access to location when open and in the background.

in my app a FAB call a method like this:

getPos(){
try{
final resp = await mGeolocator.getCurrentPosition();
} catch (e) {
print(e.toString);
}
}

in android works perfectly, but in iOS never appears requestPermission and the app closes, debug console not print any exception.

I am facing the same issue as well on my iOS Simulator. The app closes.
Working fine on an Android simulator and able to get the position.

My info.plist has:
NSLocationWhenInUseUsageDescription
This app needs access to location when open.
NSLocationAlwaysUsageDescription
This app needs access to location when in the background.
NSLocationAlwaysAndWhenInUseUsageDescription
This app needs access to location when open and in the background.

My Code:

void getLocation() async {

Position position = await Geolocator()
    .getCurrentPosition(desiredAccuracy: LocationAccuracy.low);

print(position);

}

In your Targets -> Tab Signing&Capabilites -> Add Capability -> Select Background Modes
And choose options below.

image

make sure your simulator has location enabled.
in your simulator -> Debug -> Location -> Custom Location...
image

@samo92, @vijayanbits during the weekend I published a release candidate for version 6.0.0 on pub.dev which solves a lot of problems specifically with permissions and reporting if the location services are not enabled.

I would very much appreciate it if you can give it a try and see if it solves this problem. Hope to hear from you.

Was this page helpful?
0 / 5 - 0 ratings