react-native-background-geolocation@5.0.0-beta.1
    Preparing search index...

    Interface Config

    Configuration API.

    The Config class defines all SDK options, grouped into compound configuration objects:

    Instances of Config are consumed by BackgroundGeolocation.ready and BackgroundGeolocation.setConfig.

    import BackgroundGeolocation, {
    Config,
    GeoConfig,
    ActivityConfig,
    HttpConfig,
    PersistenceConfig,
    DesiredAccuracy,
    PersistMode,
    LogLevel,
    AppConfig,
    LoggerConfig,
    State
    } from 'react-native-background-geolocation';

    async function main() {
    // Configure the SDK with compound configuration objects.
    const config: Config = {
    geolocation: {
    desiredAccuracy: DesiredAccuracy.High,
    distanceFilter: 20,
    stopTimeout: 5,
    stationaryRadius: 150,
    },
    activity: {
    disableStopDetection: false,
    motionTriggerDelay: 30000,
    },
    http: {
    url: 'https://my.server.com/api/locations',
    method: 'POST',
    autoSync: true,
    headers: {
    Authorization: 'Bearer secret-token',
    },
    params: {
    user_id: 123,
    },
    },
    persistence: {
    persistMode: PersistMode.All,
    maxDaysToPersist: 14,
    extras: { appVersion: '1.0.0' },
    },
    app: {
    stopOnTerminate: false,
    startOnBoot: true,
    enableHeadless: true
    },
    logger: {
    debug: true,
    logLevel: LogLevel.Verbose,
    logMaxDays: 3,
    },
    };

    // Apply the configuration.
    const state: State = await BackgroundGeolocation.ready(config);
    console.log('[ready] BackgroundGeolocation is configured and ready to use');

    if (!state.enabled) {
    await BackgroundGeolocation.start();
    }

    // To modify configuration after initialization, use setConfig.
    const updated: State = await BackgroundGeolocation.setConfig({
    http: {
    headers: {
    Authorization: 'Bearer new-token',
    },
    },
    logger: {
    logLevel: LogLevel.Info
    },
    });

    await BackgroundGeolocation.sync();
    }

    Hierarchy (View Summary)

    Index

    Properties

    reset?: boolean

    Reset the plugin to its initial state before applying this configuration. This is probably what you want.

    Defaults to true

    If you set this to false, the SDK will consume your Config only at the first install of your app. Thereafter, the only way to change your configuration will be to call BackgroundGeolocation.setConfig,

    You will certainly NOT want to use reset: false during development, as it will prevent your configuration changes from taking effect on subsequent app launches.

    logger?: LoggerConfig

    Logger configuration.

    geolocation?: GeoConfig

    Geolocation configuration.

    http?: HttpConfig

    HTTP configuration.

    app?: AppConfig

    App configuration.

    persistence?: PersistenceConfig

    Persistence configuration.

    activity?: ActivityConfig

    Motion Activity configuration.

    authorization?: AuthorizationConfig

    Authorization configuration.

    transistorAuthorizationToken?: TransistorAuthorizationToken

    Convenience option to automatically configures the SDK to upload locations to the Transistor Software demo server at http://tracker.transistorsoft.com (or your own local instance of background-geolocation-console)

    See TransistorAuthorizationService. This option will automatically configure the HttpConfig.url to point at the Demo server as well as well as the required AuthorizationConfig configuration.

    const token = await
    BackgroundGeolocation.findOrCreateTransistorAuthorizationToken("my-company-name", "my-username");

    BackgroundGeolocation.ready({
    transistorAuthorizationToken: token
    });

    This convenience option merely performs the following [[Authorization]] configuration automatically for you:

    // Base url to Transistor Demo Server.
    const url = "http://tracker.transistorsoft.com";

    // Register for an authorization token from server.
    const token = await
    BackgroundGeolocation.findOrCreateTransistorAuthorizationToken("my-company-name", "my-username");

    BackgroundGeolocation.ready({
    url: url + "/api/locations",
    authorization: {
    strategy: "JWT",
    accessToken: token.accessToken,
    refreshToken: token.refreshToken,
    refreshUrl: url + "/v2/refresh_token",
    refreshPayload: {
    refresh_token: "{refreshToken}"
    },
    expires: token.expires
    }
    });