Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ Geolocation.setRNConfiguration(
skipPermissionRequests: boolean;
authorizationLevel?: 'always' | 'whenInUse' | 'auto';
enableBackgroundLocationUpdates?: boolean;
showsBackgroundLocationIndicator?: boolean;
locationProvider?: 'playServices' | 'android' | 'auto';
}
) => void
Expand All @@ -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.

---
Expand Down
30 changes: 28 additions & 2 deletions ios/RNCGeolocation.mm
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ typedef NS_ENUM(NSInteger, RNCGeolocationAuthorizationLevel) {
BOOL skipPermissionRequests;
RNCGeolocationAuthorizationLevel authorizationLevel;
BOOL enableBackgroundLocationUpdates;
BOOL showsBackgroundLocationIndicator;
} RNCGeolocationConfiguration;

typedef struct {
Expand All @@ -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"]],
};
}

Expand Down Expand Up @@ -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;
}
}

}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

comment has been added from my side, execute the prior code to get the accurate result.


_locationManager.distanceFilter = distanceFilter;
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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
}
Expand All @@ -309,7 +335,7 @@ - (void)enableBackgroundLocationUpdates
RCT_REMAP_METHOD(startObserving, startObserving:(RNCGeolocationOptions)options)
{
checkLocationConfig();

if (_observingLocation) {
[self stopObserving];
}
Expand Down
2 changes: 2 additions & 0 deletions js/NativeRNCGeolocation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export type GeolocationConfiguration = {
authorizationLevel?: 'always' | 'whenInUse' | 'auto';
locationProvider?: 'playServices' | 'android' | 'auto';
enableBackgroundLocationUpdates?: boolean;
showsBackgroundLocationIndicator?: boolean;
};

export type GeolocationOptions = {
Expand Down Expand Up @@ -44,6 +45,7 @@ export interface Spec extends TurboModule {
skipPermissionRequests: boolean;
authorizationLevel?: string;
enableBackgroundLocationUpdates?: string;
showsBackgroundLocationIndicator?: string;
}): void;
requestAuthorization(
success: () => void,
Expand Down
2 changes: 2 additions & 0 deletions js/implementation.native.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ export function setRNConfiguration(config: GeolocationConfiguration) {
...config,
enableBackgroundLocationUpdates:
config?.enableBackgroundLocationUpdates ?? true,
showsBackgroundLocationIndicator:
config?.showsBackgroundLocationIndicator ?? true,
authorizationLevel:
config?.authorizationLevel === 'auto'
? undefined
Expand Down