Finished platform interface for temporary precise location
MODIFY
geolocator_platform_interface/CHANGELOG.md
geolocator_platform_interface/CHANGELOG.md
+## 2.3.0
+
+- Added the possibility to request temporary Precise Accuracy on iOS 14+ devices.
+
## 2.2.0
- Added the possibility to query for the LocationAccuracyStatus on devices running iOS 14.0 and higher.

ADD
geolocator_platform_interface/lib/src/errors/accuracy_dictionary_not_found_exception.dart
+ /// An exception thrown when the Temporary Accuracy request key is missing in
+ /// the Info.plist. The exception is only thrown on iOS.
+ class AccuracyDictionaryNotFoundException implements Exception {
+ /// Constructs the [AccuracyDictionaryNotFoundException]
+ const AccuracyDictionaryNotFoundException(this.message);
+
+ /// A [message] describing more details about the missing Dictionary key.
+ final String? message;
+
+ @override
+ String toString() {
+ if (message == null || message == '') {
+ return 'Temporary Full accuracy key or description: '
+ '\'NSLocationTemporaryUsageDescriptionDictionary\' is missing in the'
+ ' Info.plist dictionary.'
+ ;
+ }
+ return message!;
+ }
+ }
\ No newline at end of file

ADD
geolocator_platform_interface/lib/src/errors/approximate_location_not_supported_exception.dart
+/// An exception thrown when users using iOS 13 or below try to execute the
+/// 'requestTemporaryFullAccuracy' method.
+///
+/// Since Approximate location only supports iOS 14 or above, the exception is
+/// only thrown when using iOS 13 or below
+class ApproximateLocationNotSupportedException implements Exception {
+ /// Constructs the [ApproximateLocationNotSupportedException]
+ const ApproximateLocationNotSupportedException(this.message);
+
+ /// A [message] describing more details about the exception
+ final String? message;
+
+ @override
+ String toString() {
+ if(message == null || message == ''){
+ return 'The \'requestTemporaryFullAccuracy\' method only supports iOS 14'
+ 'or above.';
+ }
+ return message!;
+ }
+}
\ No newline at end of file

MODIFY
geolocator_platform_interface/lib/src/errors/errors.dart
geolocator_platform_interface/lib/src/errors/errors.dart
+export 'accuracy_dictionary_not_found_exception.dart';
export 'activity_missing_exception.dart';
export 'already_subscribed_exception.dart';
+export 'approximate_location_not_supported_exception.dart';
export 'invalid_permission_exception.dart';
export 'location_service_disabled_exception.dart';
export 'permission_definitions_not_found_exception.dart';
export 'permission_denied_exception.dart';
export 'permission_request_in_progress_exception.dart';
export 'position_update_exception.dart';
+export 'precise_accuracy_enabled_exception.dart';

ADD
geolocator_platform_interface/lib/src/errors/precise_accuracy_enabled_exception.dart
+/// An exception thrown when the user already enabled Precise Location fetching.
+///
+/// This exception is thrown only when using iOS 14 or above.
+class PreciseAccuracyEnabledException implements Exception {
+ /// Constructs the [PreciseAccuracyEnabledException]
+ const PreciseAccuracyEnabledException(this.message);
+
+ /// A [message] describing more details about the exception.
+ final String? message;
+
+ @override
+ String toString() {
+ if (message == null || message == ''){
+ return 'The user already enabled Precise location fetching, when using '
+ 'the \'requestTemporaryFullAccuracy\', make sure to check whether the'
+ 'user has already given permission to use Precise Accuracy.';
+ }
+
+ return message!;
+ }
+}
\ No newline at end of file

MODIFY
geolocator_platform_interface/lib/src/geolocator_platform_interface.dart
geolocator_platform_interface/lib/src/geolocator_platform_interface.dart
@@ -158,6 +158,19 @@ abstract class GeolocatorPlatform extends PlatformInterface {
}) {
throw UnimplementedError('getPositionStream() has not been implemented.');
}
+ /// Asks the user for Temporary Precise location access (iOS 14 or above).
+ ///
+ /// Throws a [AccuracyDictionaryNotFoundException] when the key
+ /// `NSLocationTemporaryUsageDescriptionDictionary` has not been set in the
+ /// `Infop.list`.
+ /// Throws a [PreciseAccuracyEnabledException] when the user already gave
+ /// permission to use Precise Accuracy location fetching.
+ /// Throws a [ApproximateLocationNotSupportedException] when Approximate
+ /// Location is not supported (iOS 13 or below)
+ Future<void> requestTemporaryFullAccuracy(){
+ // ignore: lines_longer_than_80_chars
+ throw UnimplementedError('requestTemporaryFullAccuracy() has not been implemented');
+ }
/// Returns a [Future] containing a [LocationAccuracyStatus].
///

MODIFY
geolocator_platform_interface/lib/src/implementations/method_channel_geolocator.dart
geolocator_platform_interface/lib/src/implementations/method_channel_geolocator.dart
@@ -225,6 +225,18 @@ class MethodChannelGeolocator extends GeolocatorPlatform {
return controller.stream.asBroadcastStream();
}
+ @override
+ Future<void> requestTemporaryFullAccuracy() async {
+ try {
+ final accuracyFuture = await _methodChannel
+ .invokeMethod('requestTemporaryFullAccuracy');
+ return accuracyFuture;
+ } on PlatformException catch (e) {
+ _handlePlatformException(e);
+ rethrow;
+ }
+ }
+
@override
Future<bool> openAppSettings() async => _methodChannel
.invokeMethod<bool>('openAppSettings')
@@ -251,6 +263,12 @@ class MethodChannelGeolocator extends GeolocatorPlatform {
throw PermissionRequestInProgressException(exception.message);
case 'LOCATION_UPDATE_FAILURE':
throw PositionUpdateException(exception.message);
+ case 'ACCURACY_DICTIONARY_NOT_FOUND':
+ throw AccuracyDictionaryNotFoundException(exception.message);
+ case 'PRECISE_ACCURACY_ENABLED':
+ throw PreciseAccuracyEnabledException(exception.message);
+ case 'APPROXIMATE_LOCATION_NOT_SUPPORTED':
+ throw ApproximateLocationNotSupportedException(exception.message);
default:
throw exception;
}

MODIFY
geolocator_platform_interface/pubspec.yaml
geolocator_platform_interface/pubspec.yaml
@@ -3,7 +3,7 @@ description: A common platform interface for the geolocator plugin.
homepage: https://github.com/baseflow/flutter-geolocator
# NOTE: We strongly prefer non-breaking changes, even at the expense of a
# less-clean API. See https://flutter.dev/go/platform-interface-breaking-changes
-version: 2.2.0
+version: 2.3.0
dependencies:
flutter:

MODIFY
geolocator_platform_interface/test/src/implementations/method_channel_geolocator_test.dart
geolocator_platform_interface/test/src/implementations/method_channel_geolocator_test.dart
@@ -134,10 +134,100 @@ void main() {
});
});
+ group(
+ // ignore: lines_longer_than_80_chars
+ 'requestTemporaryFullAccuracy: When requesting Temporary Precise location',
+ () {
+ test('Should receive an exception when precise location is enabled',
+ () async {
+ MethodChannelMock(
+ channelName: 'flutter.baseflow.com/geolocator',
+ method: 'requestTemporaryFullAccuracy',
+ result: PlatformException(
+ code: 'PRECISE_ACCURACY_ENABLED',
+ message: 'Precise location is enabled.',
+ details: null,
+ ),
+ );
+
+ // Act
+ final accuracyFuture = MethodChannelGeolocator()
+ .requestTemporaryFullAccuracy();
+
+ // Assert
+ expect(
+ accuracyFuture,
+ throwsA(
+ isA<PreciseAccuracyEnabledException>().having(
+ (e) => e.message,
+ 'description',
+ 'Precise location is enabled.',
+ ),
+ ),
+ );
+ });
+ test('Should receive an exception when iOS 13 or below is used',
+ () async {
+ MethodChannelMock(
+ channelName: 'flutter.baseflow.com/geolocator',
+ method: 'requestTemporaryFullAccuracy',
+ result: PlatformException(
+ code: 'APPROXIMATE_LOCATION_NOT_SUPPORTED',
+ message: 'Approximate location not supported.',
+ details: null,
+ ),
+ );
+
+ // Act
+ final accuracyFuture = MethodChannelGeolocator()
+ .requestTemporaryFullAccuracy();
+
+ // Assert
+ expect(
+ accuracyFuture,
+ throwsA(
+ isA<ApproximateLocationNotSupportedException>().having(
+ (e) => e.message,
+ 'description',
+ 'Approximate location not supported.',
+ ),
+ ),
+ );
+ });
+ test('Should receive an exception when the location accuracy definition'
+ ' in the Info.plist is missing',
+ () async {
+ MethodChannelMock(
+ channelName: 'flutter.baseflow.com/geolocator',
+ method: 'requestTemporaryFullAccuracy',
+ result: PlatformException(
+ code: 'ACCURACY_DICTIONARY_NOT_FOUND',
+ message: 'Accuracy definition missing.',
+ details: null,
+ ),
+ );
+
+ // Act
+ final accuracyFuture = MethodChannelGeolocator()
+ .requestTemporaryFullAccuracy();
+
+ // Assert
+ expect(
+ accuracyFuture,
+ throwsA(
+ isA<AccuracyDictionaryNotFoundException>().having(
+ (e) => e.message,
+ 'description',
+ 'Accuracy definition missing.',
+ ),
+ ),
+ );
+ });
+ });
+
group('getLocationAccuracy: When requesting the Location Accuracy Status',
() {
- test(
- 'Should receive reduced accuracy if Location Accuracy is reduced',
+ test('Should receive reduced accuracy if Location Accuracy is reduced',
() async {
// Arrange
MethodChannelMock(
@@ -154,8 +244,7 @@ void main() {
expect(locationAccuracy, LocationAccuracyStatus.reduced);
});
- test(
- 'Should receive reduced accuracy if Location Accuracy is reduced',
+ test('Should receive reduced accuracy if Location Accuracy is reduced',
() async {
// Arrange
MethodChannelMock(
@@ -171,7 +260,6 @@ void main() {
// Assert
expect(locationAccuracy, LocationAccuracyStatus.precise);
});
-
});
group('requestPermission: When requesting for permission', () {

Finished platform interface for temporary precise location