Skip to content

App

public classApp

Background-task and power-save utilities.

Access via BGGeo.instance.app.


Members

createBackgroundTask

func startBackgroundTask() async throws -> Double

Signal to the OS that you need to perform a long-running task.

The OS keeps the app running in the background until you signal completion with stopBackgroundTask. Your callback receives a taskId which you must pass to stopBackgroundTask when finished — always call it, even if an error occurs, to avoid hanging the background task.

iOS

Uses beginBackgroundTaskWithExpirationHandler. iOS provides exactly 180 seconds of background time. The SDK automatically stops the task before the OS force-kills the app.

✅-[BackgroundTaskManager createBackgroundTask] 1
✅-[BackgroundTaskManager stopBackgroundTask:]_block_invoke 1 OF (1)
Android

Uses WorkManager. The SDK imposes a 3-minute limit before automatically force-killing the task.

 I TSLocationManager: [c.t.l.u.BackgroundTaskManager onStartJob] ⏳ startBackgroundTask: 6
 I TSLocationManager: [c.t.l.u.BackgroundTaskManager$Task stop] ⏳ stopBackgroundTask: 6
let bgGeo = BGGeo.shared
let subscription = bgGeo.onLocation { location in
    print("[location] \(location)")

    // Perform some long-running task (eg: HTTP request)
    let taskId = bgGeo.app.createBackgroundTask()
    // Perform your long-running task here
    print("[backgroundTask] executing taskId: \(taskId)")
    // When your long-running task is complete, signal completion of taskId.
    bgGeo.app.stopBackgroundTask(taskId)
}

stopBackgroundTask

public func stopBackgroundTask(_ taskId: UIBackgroundTaskIdentifier)

Signal completion of a startBackgroundTask to the OS.

The OS may now suspend the app if appropriate.

let bgGeo = BGGeo.shared
// Perform some long-running task (e.g., HTTP request)
let taskId = bgGeo.app.createBackgroundTask()
// Perform your long-running task here
print("[backgroundTask] executing taskId: \(taskId)")
// When your long-running task is complete, signal completion of taskId.
bgGeo.app.stopBackgroundTask(taskId)