npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@ajuarezso/capacitor-native-location-auth

v1.0.2

Published

Capacitor plugin to distinguish the 4 real levels of location authorization (notDetermined / whenInUse / always / denied) on iOS and Android. Fills the gap of @capacitor/geolocation which only reports generic granted/denied without distinguishing foregrou

Readme

@ajuarezso/capacitor-native-location-auth

Capacitor plugin to distinguish the 4 real levels of location authorization (notDetermined / whenInUse / always / denied) on iOS and Android. Fills the gap left by @capacitor/geolocation which only reports generic granted / denied. Free alternative to @transistorsoft/capacitor-background-geolocation ($300/year on Android).

npm version license

🇪🇸 Versión en español: README.es.md

Capacitor plugin to distinguish the 4 real levels of location authorization (notDetermined / whenInUse / always / denied) on iOS and Android.

Fills the gap left by @capacitor/geolocation, which only reports generic granted / denied / prompt without distinguishing foreground vs background.

Designed for apps that need to build a 2-step educational permission flow:

  1. Ask user for whenInUse first (foreground only) — iOS shows a simple dialog with no "Always" option mixed in.
  2. After foreground granted, ask for always (background) — iOS shows a dedicated upgrade dialog ("Allow always" vs "Keep while using").

This is the UX flow Apple recommends and that apps like Uber, Rappi, and DoorDash use.

Install

npm install @ajuarezso/capacitor-native-location-auth
npx cap sync

iOS Setup

In ios/App/App/Info.plist, ensure you have both keys:

<key>NSLocationWhenInUseUsageDescription</key>
<string>Your app needs location to ...</string>
<key>NSLocationAlwaysAndWhenInUseUsageDescription</key>
<string>Your app needs background location to ...</string>

If you need background tracking, also add location to UIBackgroundModes.

Android Setup

In android/app/src/main/AndroidManifest.xml:

<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" />

ACCESS_BACKGROUND_LOCATION is only needed for Android 10+ (API 29+).

API

Types

type LocationAuthStatus = 'notDetermined' | 'whenInUse' | 'always' | 'denied';

interface LocationAuthStatusResult {
  status: LocationAuthStatus;
}

getStatus(): Promise<LocationAuthStatusResult>

Returns the current authorization level without prompting.

import { NativeLocationAuth } from '@ajuarezso/capacitor-native-location-auth';

const { status } = await NativeLocationAuth.getStatus();
// 'notDetermined' | 'whenInUse' | 'always' | 'denied'

requestWhenInUse(): Promise<LocationAuthStatusResult>

Requests foreground-only authorization ("While using the app").

  • iOS: calls CLLocationManager.requestWhenInUseAuthorization(). Shows a system dialog with only whenInUse / oneTime / denynot the combined 4-option dialog that Geolocation.requestPermissions() would show.
  • Android: requests ACCESS_FINE_LOCATION.

If status is already whenInUse or always, resolves immediately without showing a dialog. If permanently denied, returns 'denied' and you should direct user to Settings.

const { status } = await NativeLocationAuth.requestWhenInUse();
if (status === 'whenInUse') {
  // Now you can ask for 'always' separately
}

requestAlways(): Promise<LocationAuthStatusResult>

Requests background authorization ("Always allow"). Call this after requestWhenInUse() succeeded.

  • iOS: calls CLLocationManager.requestAlwaysAuthorization(). If status is whenInUse, iOS shows the upgrade dialog ("Allow always" vs "Keep while using"). If user already denied, no dialog is shown — only Settings can change it.
  • Android 10+: requests ACCESS_BACKGROUND_LOCATION with its own runtime dialog ("Allow all the time" vs "Allow only while using").
  • Android <10: resolves immediately with 'always' because background isn't a separate permission below API 29.
const { status } = await NativeLocationAuth.requestAlways();
if (status === 'always') {
  // Start background tracking
}

Complete 2-step Flow Example

import { NativeLocationAuth } from '@ajuarezso/capacitor-native-location-auth';

async function enableBackgroundLocation() {
  const initial = await NativeLocationAuth.getStatus();

  if (initial.status === 'always') {
    // Already authorized for background; start tracking
    return startTracking();
  }

  if (initial.status === 'denied') {
    // Permanently denied; direct user to Settings
    return openSettings();
  }

  // Step 1: ask for foreground
  await showEducationalModal({ title: 'Enable location', cta: 'Continue' });
  const fg = await NativeLocationAuth.requestWhenInUse();
  if (fg.status === 'denied') return openSettings();

  // Step 2: ask for background
  await showEducationalModal({ title: 'One more permission', cta: 'Continue' });
  const bg = await NativeLocationAuth.requestAlways();
  if (bg.status === 'always') {
    startTracking();
  } else {
    // User kept only whenInUse — start tracking anyway,
    // they'll just need to keep the app open
    startTracking({ foregroundOnly: true });
  }
}

Why This Plugin?

The official @capacitor/geolocation plugin reports permission as a generic granted / denied — you cannot tell whether the user has whenInUse or always. This is fine for apps that only need foreground location, but breaks for apps that need background tracking (delivery drivers, fitness apps, geofencing, etc.).

Other plugins:

| Plugin | Distinguishes whenInUse vs always? | Cost | |---|---|---| | @capacitor/geolocation | ❌ | Free | | @capacitor-community/background-geolocation | ❌ | Free | | @capgo/background-geolocation | ❌ | Free | | @transistorsoft/capacitor-background-geolocation | ✅ | $300/year for Android production | | @ajuarezso/capacitor-native-location-auth | ✅ | Free |

Platforms

  • iOS 14+
  • Android API 24+ (Android 7+)

Keywords for discoverability

This plugin solves: capacitor location permission whenInUse vs always, capacitor background location, capacitor foreground vs background geolocation, capacitor CLLocationManager requestWhenInUse, capacitor CLLocationManager requestAlways, capacitor 2-step location permission flow, capacitor Uber Rappi DoorDash style permission flow, capacitor location authorization status, ionic background location free alternative transistorsoft, capacitor Apple location permission flow, capacitor ACCESS_BACKGROUND_LOCATION runtime.

Related projects this is an alternative to or complements:

  • @capacitor/geolocation (no distinguishes auth levels)
  • @capacitor-community/background-geolocation (no distinguishes auth levels)
  • @capgo/background-geolocation (use this for the actual tracking — pair with native-location-auth for the permission flow)
  • @transistorsoft/capacitor-background-geolocation (paid alternative that has its own permission API)

Repository

  • Source: https://github.com/anthonyjuarezsolis/capacitor-native-location-auth
  • Issues: https://github.com/anthonyjuarezsolis/capacitor-native-location-auth/issues
  • npm: https://www.npmjs.com/package/@ajuarezso/capacitor-native-location-auth
  • Built and used in production by Master Pedidos

License

MIT — see LICENSE.