requestTemporaryFullAccuracy method Null safety

Future<int> requestTemporaryFullAccuracy(
  1. String purpose
)

[iOS 14+] iOS 14 has introduced a new [Precise: On] switch on the location authorization dialog allowing users to disable high-accuracy location.

The method requestTemporaryFullAccuracy (Apple docs) will allow you to present a dialog to the user requesting temporary full accuracy for the lifetime of this application run (until terminate).

Configuration — Info.plist

In order to use this method, you must configure your Info.plist with the Dictionary key: Privacy - Location Temporary Usage Description Dictionary

The keys of this Dictionary (eg: Delivery) are supplied as the first argument to the method. The value will be printed on the dialog shown to the user, explaing the purpose of your request for full accuracy.

If the dialog fails to be presented, an error will be thrown:

  • The Info.plist file doesn’t have an entry for the given purposeKey value.
  • The app is already authorized for full accuracy.
  • The app is in the background.

Example

BackgroundGeolocation.onProviderChange((ProviderChangeEvent event) {
  if (event.accuracyAuthorization == ProviderChangeEvent.ACCURACY_AUTHORIZATION_REDUCED) {
    // Supply "Purpose" key from Info.plist as 1st argument.
    BackgroundGeolocation.requestTemporaryFullAccuracy("Delivery").then((int accuracyAuthorization) {
      if (accuracyAuthorization == ProviderChangeEvent.ACCURACY_AUTHORIZATION_FULL) {
        print("[requestTemporaryFullAccuracy] GRANTED:  $accuracyAuthorization");
      } else {
        print("[requestTemporaryFullAccuracy] DENIED:  $accuracyAuthorization");
      }
    }).catchError((error) {
      print("[requestTemporaryFullAccuracy] FAILED TO SHOW DIALOG: $error");
    });
  }
});

See also:

Implementation

static Future<int> requestTemporaryFullAccuracy(String purpose) async {
  return (await _methodChannel.invokeMethod<int>(
      'requestTemporaryFullAccuracy', purpose))!;
}