From a44ac57a5630633fb9753e2943c216014a37e113 Mon Sep 17 00:00:00 2001 From: "Laid Feggaa ( Rabi3 )" Date: Thu, 3 Oct 2024 17:01:49 +0400 Subject: [PATCH] add showsBackgroundLocationIndicator in ios --- README.md | 2 ++ ios/RNCGeolocation.mm | 30 ++++++++++++++++++++++++++++-- js/NativeRNCGeolocation.ts | 2 ++ js/implementation.native.ts | 2 ++ 4 files changed, 34 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 6a37550..f2d0302 100644 --- a/README.md +++ b/README.md @@ -172,6 +172,7 @@ Geolocation.setRNConfiguration( skipPermissionRequests: boolean; authorizationLevel?: 'always' | 'whenInUse' | 'auto'; enableBackgroundLocationUpdates?: boolean; + showsBackgroundLocationIndicator?: boolean; locationProvider?: 'playServices' | 'android' | 'auto'; } ) => void @@ -182,6 +183,7 @@ Supported options: * `skipPermissionRequests` (boolean) - Defaults to `false`. If `true`, you must request permissions before using Geolocation APIs. * `authorizationLevel` (string, iOS-only) - Either `"whenInUse"`, `"always"`, or `"auto"`. Changes whether the user will be asked to give "always" or "when in use" location services permission. Any other value or `auto` will use the default behaviour, where the permission level is based on the contents of your `Info.plist`. * `enableBackgroundLocationUpdates` (boolean, iOS-only) - When using `skipPermissionRequests`, toggle wether to automatically enableBackgroundLocationUpdates. Defaults to true. +* `showsBackgroundLocationIndicator` (boolean, iOS-only) - When You are running app in background * `locationProvider` (string, Android-only) - Either `"playServices"`, `"android"`, or `"auto"`. Determines wether to use `Google’s Location Services API` or `Android’s Location API`. The `"auto"` mode defaults to `android`, and falls back to Android's Location API if play services aren't available. --- diff --git a/ios/RNCGeolocation.mm b/ios/RNCGeolocation.mm index 03df64d..b10149c 100644 --- a/ios/RNCGeolocation.mm +++ b/ios/RNCGeolocation.mm @@ -39,6 +39,7 @@ typedef NS_ENUM(NSInteger, RNCGeolocationAuthorizationLevel) { BOOL skipPermissionRequests; RNCGeolocationAuthorizationLevel authorizationLevel; BOOL enableBackgroundLocationUpdates; + BOOL showsBackgroundLocationIndicator; } RNCGeolocationConfiguration; typedef struct { @@ -64,7 +65,9 @@ + (RNCGeolocationConfiguration)RNCGeolocationConfiguration:(id)json return (RNCGeolocationConfiguration) { .skipPermissionRequests = [RCTConvert BOOL:options[@"skipPermissionRequests"]], - .authorizationLevel = [RCTConvert RNCGeolocationAuthorizationLevel:options[@"authorizationLevel"]] + .authorizationLevel = [RCTConvert RNCGeolocationAuthorizationLevel:options[@"authorizationLevel"]], + .enableBackgroundLocationUpdates = [RCTConvert BOOL:options[@"enableBackgroundLocationUpdates"]], + .showsBackgroundLocationIndicator = [RCTConvert BOOL:options[@"showsBackgroundLocationIndicator"]], }; } @@ -182,6 +185,14 @@ - (void)beginLocationUpdatesWithDesiredAccuracy:(CLLocationAccuracy)desiredAccur if (!_locationManager) { _locationManager = [CLLocationManager new]; _locationManager.delegate = self; + + if(_locationConfiguration.showsBackgroundLocationIndicator) { + // Set showsBackgroundLocationIndicator to YES + if ([_locationManager respondsToSelector:@selector(setShowsBackgroundLocationIndicator:)]) { + _locationManager.showsBackgroundLocationIndicator = YES; + } + } + } _locationManager.distanceFilter = distanceFilter; @@ -252,6 +263,14 @@ - (void)timeout:(NSTimer *)timer if (!_locationManager) { _locationManager = [CLLocationManager new]; _locationManager.delegate = self; + + if(_locationConfiguration.showsBackgroundLocationIndicator) { + // Set showsBackgroundLocationIndicator to YES + if ([_locationManager respondsToSelector:@selector(setShowsBackgroundLocationIndicator:)]) { + _locationManager.showsBackgroundLocationIndicator = YES; + } + } + } if (successBlock != nil || errorBlock != nil) { @@ -301,6 +320,13 @@ - (void)enableBackgroundLocationUpdates if ([_locationManager respondsToSelector:@selector(setAllowsBackgroundLocationUpdates:)]) { [_locationManager setAllowsBackgroundLocationUpdates:YES]; } + + if(_locationConfiguration.showsBackgroundLocationIndicator) { + // Set showsBackgroundLocationIndicator to YES + if ([_locationManager respondsToSelector:@selector(setShowsBackgroundLocationIndicator:)]) { + _locationManager.showsBackgroundLocationIndicator = YES; + } + } } #endif } @@ -309,7 +335,7 @@ - (void)enableBackgroundLocationUpdates RCT_REMAP_METHOD(startObserving, startObserving:(RNCGeolocationOptions)options) { checkLocationConfig(); - + if (_observingLocation) { [self stopObserving]; } diff --git a/js/NativeRNCGeolocation.ts b/js/NativeRNCGeolocation.ts index 8f6ab11..31acdd2 100644 --- a/js/NativeRNCGeolocation.ts +++ b/js/NativeRNCGeolocation.ts @@ -6,6 +6,7 @@ export type GeolocationConfiguration = { authorizationLevel?: 'always' | 'whenInUse' | 'auto'; locationProvider?: 'playServices' | 'android' | 'auto'; enableBackgroundLocationUpdates?: boolean; + showsBackgroundLocationIndicator?: boolean; }; export type GeolocationOptions = { @@ -44,6 +45,7 @@ export interface Spec extends TurboModule { skipPermissionRequests: boolean; authorizationLevel?: string; enableBackgroundLocationUpdates?: string; + showsBackgroundLocationIndicator?: string; }): void; requestAuthorization( success: () => void, diff --git a/js/implementation.native.ts b/js/implementation.native.ts index 53b3c76..96d5c40 100644 --- a/js/implementation.native.ts +++ b/js/implementation.native.ts @@ -46,6 +46,8 @@ export function setRNConfiguration(config: GeolocationConfiguration) { ...config, enableBackgroundLocationUpdates: config?.enableBackgroundLocationUpdates ?? true, + showsBackgroundLocationIndicator: + config?.showsBackgroundLocationIndicator ?? true, authorizationLevel: config?.authorizationLevel === 'auto' ? undefined