AFBackground Tasks
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:
Info.plist — add the task identifier under
BGTaskSchedulerPermittedIdentifiers:<key>BGTaskSchedulerPermittedIdentifiers</key>
<array>
<string>com.advantahealth.afcore.outbox-flush</string>
</array>Content copied to clipboardAlso ensure the Background Modes → Background fetch capability is enabled in the target.
AppDelegate /
@main— call registerHandler beforeapplication(_:didFinishLaunchingWithOptions:)returns:func application(_ application: UIApplication,
didFinishLaunchingWithOptions: …) -> Bool {
AFBackgroundTasks.shared.registerHandler()
AFCore.shared.initialize(config)
AFBackgroundTasks.shared.scheduleNext()
return true
}Content copied to clipboard
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
Functions
Register the SDK's handler with BGTaskScheduler. Must be called before application(_:didFinishLaunchingWithOptions:) returns — iOS rejects registrations attempted later.
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.