Skip to content

[Feature]: Expose location authorization change events #195

Description

@chanphiromsok

Feature Description

Please add an event listener that notifies apps when the device’s location authorization or provider state changes.

A possible API could be:

const subscription = NitroGeolocation.onProviderChange((event) => {
  switch (event.status) {
    case NitroGeolocation.AuthorizationStatus.Denied:
      console.log("Location authorization denied");
      break;

    case NitroGeolocation.AuthorizationStatus.Always:
      console.log("Location always granted");
      break;

    case NitroGeolocation.AuthorizationStatus.WhenInUse:
      console.log("Location when-in-use granted");
      break;
  }
});

// Cleanup
subscription.remove();

The exact API naming can follow this library’s conventions. The key need is a subscription-based way to react to permission changes made in system settings while the application is running or when it returns to the foreground.

Use Case

Apps that rely on continuous or background location need to know immediately when the user changes location permissions.

For example, a user might:

  • Deny location permission.
  • Revoke permission later in device Settings.
  • Change iOS permission from Always Allow to While Using the App.
  • Re-enable location authorization after it was previously denied.

Without an authorization-change event, apps must repeatedly poll for permissions or wait for location requests to fail. That can result in silent failures, unreliable background tracking, and unclear guidance for users.

Proposed Solution

Expose a listener similar to onProviderChange that emits the latest authorization state whenever it changes.

Suggested event shape:

type ProviderChangeEvent = {
  status:
    | AuthorizationStatus.Denied
    | AuthorizationStatus.Always
    | AuthorizationStatus.WhenInUse;
};

Expected behavior:

  • Emit Denied when location authorization is unavailable or revoked.
  • Emit Always when background-capable location access is granted.
  • Emit WhenInUse on iOS when the user grants foreground-only access.
  • Provide a subscription cleanup method to prevent memory leaks.
  • Support both iOS and Android where the platforms expose equivalent authorization changes.

This would allow applications to pause location-dependent behavior, show permission guidance, or resume tracking as soon as the relevant state changes.

Alternatives Considered

  • Checking permissions only at application startup: does not catch later changes made in system settings.
  • Polling permission status: adds unnecessary complexity and can delay the app’s response.
  • Waiting for location operations to fail: produces a poor user experience because the app discovers the problem only after attempting to use location.
  • Using app-state changes only: helps when returning from Settings, but does not provide a dedicated, reliable authorization-change event.

Additional Context

A similar API exists in Transistorsoft’s React Native Background Geolocation library:

const subscription = BackgroundGeolocation.onProviderChange((event) => {
  switch (event.status) {
    case BackgroundGeolocation.AuthorizationStatus.Denied:
      console.log("Location authorization denied");
      break;

    case BackgroundGeolocation.AuthorizationStatus.Always:
      console.log("Location always granted");
      break;

    case BackgroundGeolocation.AuthorizationStatus.WhenInUse:
      console.log("Location when-in-use granted");
      break;
  }
});

Reference: Transistorsoft React Native Background Geolocation — onProviderChange

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions