0

My flutter is compiling and running on the simulator which is iPhone 11 (13.4). I'm invoking geolocator like so:

geolocator
         .getCurrentPosition(desiredAccuracy: LocationAccuracy.best)
         .then((Position position) {
       setState(() {
         _currentPosition = LGPSHelper.gpsToString(
             new GeoPoint( position.latitude, position.longitude ) );
       });
     }).catchError((e) {
       print(e);
     });

It is catching the following error:

flutter: PlatformException(ERROR_MISSING_PROPERTYKEY, To use location in iOS8 you need to define either NSLocationWhenInUseUsageDescriptionor NSLocationAlwaysUsageDescription in the app bundle's Info.plist file, null)

I have the target iOS set to 13.0 everywhere I can think of, but still the iOS8 error persists. I know I could just add the parameter, but it makes me nervous that somewhere the build thinks I'm targeting iOS8. I've cleaned, rebuilt, etc. Any suggestions?

  • That isn't what the message is saying. It is saying that to use location in iOS8 (and later) you need to include the required location usage privacy strings in your info.plist file. I've never used Flutter so I can't tell you how to do that but googling "flutter info.plist location" will probably get you started. Perhaps you could file a bug with Google to change that message to say "iOS8 and later..." – Paulw11 Apr 19 '20 at 21:46
  • see this it may be similar: https://stackoverflow.com/a/24063578/9142279 – HII Apr 19 '20 at 22:15

1 Answers1

1

You need to add the required key in your Info.plist file in the iOS project as you will have problems publishing to the app store without these required permission keys. As for why it is still targeting iOS 8, you need to change the target within xcode, not within build files as a lot of them are generated by xcode during build.

To do so open ios/Runner/Info.plist and add the following:

<key>NSLocationWhenInUseUsageDescription</key>
<string>This app needs access to location when open.</string>

And if you plan to support iOS 10 or earlier also add:

<key>NSLocationAlwaysUsageDescription</key>
<string>This app needs access to location when in the background.</string>
<key>NSLocationAlwaysAndWhenInUseUsageDescription</key>
<string>This app needs access to location when open and in the background.</string>

You can customize the strings to better fit your app. I would also recommend setting the build target back to iOS 9.0 since you want to support as many devices as possible, and I have found 9 to be more stable with most flutter packages over 8.

Jwildsmith
  • 1,015
  • 2
  • 9
  • 15