AFBackgroundTasks

iOS-only helper for draining the SDK's event outbox while the app is suspended.

iOS does not allow third-party code to wake the app on a timer unilaterally. The supported path is BGTaskScheduler — a small budget of background-refresh slots the OS doles out based on the user's historical app usage. The SDK uses one of those slots to drain the outbox: when the OS grants the task, we call EventOutbox.flushAsync and queue the next request before yielding the slot back to the OS.

Consumer setup

Two pieces are required in the host app because BGTaskScheduler is registered at app-launch time, before AFCore is fully initialized:

  1. Info.plist — add the task identifier under BGTaskSchedulerPermittedIdentifiers:

     <key>BGTaskSchedulerPermittedIdentifiers</key>
    <array>
    <string>com.advantahealth.afcore.outbox-flush</string>
    </array>

    Also ensure the Background Modes → Background fetch capability is enabled in the target.

  2. AppDelegate / @main — call registerHandler before application(_:didFinishLaunchingWithOptions:) returns:

     func application(_ application: UIApplication,
    didFinishLaunchingWithOptions: …) -> Bool {
    AFBackgroundTasks.shared.registerHandler()
    AFCore.shared.initialize(config)
    AFBackgroundTasks.shared.scheduleNext()
    return true
    }

iOS will not deliver the task unless both pieces are in place. registerHandler is a no-op on calls after the first one, so it's safe to invoke even in apps that call AFCore.initialize multiple times during launch.

Properties

Link copied to clipboard

The identifier under which the outbox-flush task is registered. Consumer apps must list this value in BGTaskSchedulerPermittedIdentifiers in Info.plist.

Functions

Link copied to clipboard

Register the SDK's handler with BGTaskScheduler. Must be called before application(_:didFinishLaunchingWithOptions:) returns — iOS rejects registrations attempted later.

Link copied to clipboard

Submit a request for the next refresh window. The OS schedules the actual run opportunistically based on user behavior — the earliestBeginSeconds value is a lower bound, not a target.