getLocationServiceAuthorization method

Future<LocationAuthorizationStatus> getLocationServiceAuthorization()

Get the current location service authorization (Only on iOS).

This method will throw a PlatformException on Android.

Returns a LocationAuthorizationStatus. If the returned value is LocationAuthorizationStatus.notDetermined, a subsequent requestLocationServiceAuthorization call can request the authorization. If the returned value is not LocationAuthorizationStatus.notDetermined, a subsequent requestLocationServiceAuthorization will not initiate another request. It will instead return the "determined" status.

This method is a helper to get the location authorization that is necessary for certain functionality of this plugin. It can be replaced with other permission handling code/plugin if preferred.

Starting from iOS 13, getWifiBSSID and getWifiIP will only work properly if:

  • The app uses Core Location, and has the user’s authorization to use location information.
  • The app uses the NEHotspotConfiguration API to configure the current Wi-Fi network.
  • The app has active VPN configurations installed.

If the app falls into the first category, call this method before calling getWifiBSSID or getWifiIP. For example,

if (Platform.isIOS) {
  LocationAuthorizationStatus status = await _networkInfo.getLocationServiceAuthorization();
  if (status == LocationAuthorizationStatus.authorizedAlways || status == LocationAuthorizationStatus.authorizedWhenInUse) {
    wifiBSSID = await _networkInfo.getWifiName();
  } else {
    print('location service is not authorized, the data might not be correct');
    wifiBSSID = await _networkInfo.getWifiName();
  }
} else {
  wifiBSSID = await _networkInfo.getWifiName();
}

See also requestLocationServiceAuthorization for requesting a location service authorization.

Implementation

Future<LocationAuthorizationStatus> getLocationServiceAuthorization() {
  return _platform.getLocationServiceAuthorization();
}