Skip to content

ConfigΒΆ

public classConfig

Root configuration object passed to BGGeo.ready and BGGeo.setConfig.

Config groups all SDK options into typed sub-interfaces. Each key maps to a dedicated configuration area β€” set only the keys relevant to your use case.

ContentsΒΆ

OverviewΒΆ
Key Type Description
geolocation GeolocationConfig Accuracy, sampling, elasticity, stop-detection, permissions, and geofencing.
activity ActivityConfig Motion recognition, stop-detection triggers, and motion-trigger delay.
http HttpConfig Upload URL, sync cadence, batching, headers, and params.
persistence PersistenceConfig SQLite storage, TTL, record limits, and custom extras.
app AppConfig App lifecycle β€” background operation, boot behaviour, headless mode, and foreground notification.
logger LoggerConfig Debug logging, log level, and log retention.
authorization AuthorizationConfig JWT and SAS token management with automatic refresh.

The SDK persists its configuration across app launches. Call BGGeo.ready once at startup β€” subsequent launches load the persisted config automatically. Use BGGeo.setConfig to update individual keys at runtime without restarting.


ExamplesΒΆ
let bgGeo = BGGeo.shared

bgGeo.ready { config in
    config.geolocation.desiredAccuracy = kCLLocationAccuracyBest
    config.geolocation.distanceFilter = 20
    config.geolocation.stopTimeout = 5
    config.geolocation.stationaryRadius = 150

    config.activity.disableStopDetection = false

    config.http.url = "https://my.server.com/api/locations"
    config.http.method = .post
    config.http.autoSync = true
    config.http.headers = ["Authorization": "Bearer secret-token"]
    config.http.params = ["user_id": 123]

    config.persistence.persistMode = .all
    config.persistence.maxDaysToPersist = 14
    config.persistence.extras = ["appVersion": "1.0.0"]

    config.app.stopOnTerminate = false
    config.app.startOnBoot = true

    config.logger.debug = true
    config.logger.logLevel = .verbose
    config.logger.logMaxDays = 3
}

print("[ready] BackgroundGeolocation is configured and ready to use")

if !bgGeo.enabled {
    Task { try await bgGeo.start() }
}

// To modify configuration after initialization, use config.batchUpdate.
bgGeo.config.batchUpdate { config in
    config.http.headers = ["Authorization": "Bearer new-token"]
    config.logger.logLevel = .info
}

Task { try await bgGeo.store.sync() }

MembersΒΆ

activityΒΆ

public let activity:BGGeo.ActivityConfig

Motion recognition, stop-detection triggers, and motion-trigger delay. Access via BGGeo.instance.config.activity. See ActivityConfig.

appΒΆ

public let app:BGGeo.AppConfig

App lifecycle, background operation, boot behaviour, headless mode, and foreground notification. Access via BGGeo.instance.app. See AppConfig.

authorizationΒΆ

public let authorization:BGGeo.AuthorizationConfig

JWT and SAS token management with automatic refresh. Access via BGGeo.instance.authorization. See AuthorizationConfig.

geolocationΒΆ

public let geolocation:BGGeo.GeolocationConfig

Accuracy, sampling, elasticity, stop-detection, permissions, and geofencing. Access via BGGeo.instance.config.geolocation. See GeolocationConfig.

httpΒΆ

public let http:BGGeo.HttpConfig

Upload URL, HTTP method, sync cadence, batching, headers, and params. Access via BGGeo.instance.config.http. See HttpConfig.

loggerΒΆ

public let logger:BGGeo.LoggerConfig

Debug logging, log level, and log retention. Access via BGGeo.instance.config.logger. See LoggerConfig.

persistenceΒΆ

public let persistence:BGGeo.PersistenceConfig

SQLite storage, TTL, record limits, and custom extras. Access via BGGeo.instance.config.persistence. See PersistenceConfig.

resetΒΆ

public func reset()

Controls whether the SDK resets to factory defaults before applying this configuration. Defaults to true.

When true (the default), every call to BGGeo.ready applies the supplied Config on top of fresh defaults. When false, the SDK applies the supplied Config only on the first install. On subsequent launches it ignores the Config argument entirely β€” the only way to change settings is via BGGeo.setConfig.

Warning

During development, always leave reset: true (or omit it). Setting reset: false causes the SDK to ignore your Config after the first launch, so configuration changes made between development builds will not take effect.