BackgroundTaskOptions
Tells the OS how often a background task may run and what the device must have (a network, a charger) before it does.
Verwendung
Skip work when a background run has no time left.
Dieser Typ wird verwendet von backgroundTasks.schedule
// Skip work when a background run has no time left.
import { backgroundTasks, type BackgroundTaskRun, type BackgroundTaskStatus } from 'kuito';
backgroundTasks.define('refresh', async (run: BackgroundTaskRun) => {
if (run.deadline - Date.now() < 5000) return;
const response = await fetch('https://example.com/feed', { signal: AbortSignal.timeout(4000) });
if (!response.ok) throw new Error(`Refresh failed: ${response.status}`);
});
export async function enableRefresh() {
const status: BackgroundTaskStatus = await backgroundTasks.status();
if (status === 'available') await backgroundTasks.schedule('refresh');
}
// Declare refresh in kuito.config.ts before rebuilding the native app.Typdeklaration
export type BackgroundTaskOptions = {
/** Minutes between runs, at least 15 (Android's floor). The OS may wait longer. Defaults to 15. */
minimumInterval?: number;
/** Run only with a network connection. */
requiresNetwork?: boolean;
/** Run only while charging. On iOS this makes it a processing task (docs/background-tasks.md). */
requiresCharging?: boolean;
};Mitglieder 3
| Name | Typ | Erforderlich | Beschreibung |
|---|---|---|---|
minimumInterval | number | Nein | Minutes between runs, at least 15 (Android's floor). The OS may wait longer. Defaults to 15. |
requiresNetwork | boolean | Nein | Run only with a network connection. |
requiresCharging | boolean | Nein | Run only while charging. On iOS this makes it a processing task (docs/background-tasks.md). |
Generiert aus den öffentlichen TypeScript-Deklarationen: Signaturen, Props und Standardwerte stammen aus der geprüften Quelle, Beschreibungen aus deren JSDoc. Kein Standardwert ist erfunden.