Token导航 LogoToken导航TokenDH.com
前端设计权限需确认github未标认证来源可访问clear审计未展示

axiom-background-processing-refaxiom 后台处理参考

Agent Skill

用于辅助前端页面、组件、样式和交互逻辑的开发与维护。它适合让 Agent 生成或审查 React、Next.js、Vue、Tailwind、CSS 等相关代码,整理组件结构,或定位布局和性能问题。使用时需要结合项目现有设计系统、路由和构建方式,避免只生成孤立片段;涉及页面改动时,应配合本地预览和构建检查确认视觉效果。

总安装

4,137

周安装

169

GitHub Stars

873

下载量

1,325
CodexClaudeCursorGemini CLI

安装说明

本站只整理中文说明和来源信息,不托管安装包,也不代用户安装。

GitHub

来源数

3

许可证

MIT

最后核验

2026-05-01

来源状态

来源可访问

安装方式

通过对话安装

复制提示词发给支持本地命令或 Skills 的 AI 助手,先确认命令和权限,再让它执行。

请帮我安装这个 Agent Skill:axiom-background-processing-ref(axiom 后台处理参考)
来源仓库:https://github.com/charleswiltgen/axiom
仓库路径:skills/axiom-background-processing-ref
安装命令:
npx skills add https://github.com/charleswiltgen/axiom --skill axiom-background-processing-ref
安装前请先检查当前环境是否支持对应 CLI,并向我确认将要执行的命令、安装目录、联网范围和文件读写权限;确认后再执行。

命令行安装

复制命令到本机终端执行。不同来源提供的安装方式可能略有差异;本站展示可直接复制的安装命令,安装前请核对来源页面。

skills.shnpx skills
npx skills add https://github.com/charleswiltgen/axiom --skill axiom-background-processing-ref

简介

提供后台任务相关 API 接口与参数说明。

  • 适用于查阅 BGTaskScheduler 提交、续期与任务类型定义细节。
  • 支持快速查找 identifier 命名规范与调度策略说明。
  • 因无 SKILL.md 内容,请以 GitHub 仓库为准进行核实。
  • axiom-background-processing-ref 属于前端设计类 Skill,可作为该场景下的辅助能力补充。

SKILL.md

Background Processing Reference

Complete API reference for iOS background execution, with code examples from WWDC sessions.

Related skills: axiom-background-processing (decision trees, patterns), axiom-background-processing-diag (troubleshooting)


Part 1: BGTaskScheduler Registration

Info.plist Configuration

<!-- Required: List all task identifiers -->
<key>BGTaskSchedulerPermittedIdentifiers</key>
<array>
    <string>com.yourapp.refresh</string>
    <string>com.yourapp.maintenance</string>
    <!-- Wildcard for dynamic identifiers (iOS 26+) -->
    <string>com.yourapp.export.*</string>
</array>

<!-- Required: Enable background modes -->
<key>UIBackgroundModes</key>
<array>
    <!-- For BGAppRefreshTask -->
    <string>fetch</string>
    <!-- For BGProcessingTask -->
    <string>processing</string>
</array>

Register Handler

import BackgroundTasks

func application(
    _ application: UIApplication,
    didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {

    // Register BEFORE returning from didFinishLaunching
    BGTaskScheduler.shared.register(
        forTaskWithIdentifier: "com.yourapp.refresh",
        using: nil  // nil = system creates serial background queue
    ) { task in
        self.handleAppRefresh(task: task as! BGAppRefreshTask)
    }

    BGTaskScheduler.shared.register(
        forTaskWithIdentifier: "com.yourapp.maintenance",
        using: nil
    ) { task in
        self.handleMaintenance(task: task as! BGProcessingTask)
    }

    return true
}

Parameters:

  • forTaskWithIdentifier: Must match Info.plist exactly (case-sensitive)
  • using: DispatchQueue for handler callback; nil = system creates one
  • launchHandler: Called when task is launched; receives BGTask subclass

Registration Timing

From WWDC 2019-707:

"You do this by registering a launch handler before your application finishes launching"

Register in:

  • application(_:didFinishLaunchingWithOptions:) before return true
  • ❌ Not in viewDidLoad, button handlers, or async callbacks

Part 2: BGAppRefreshTask

Purpose

Keep app content fresh throughout the day. System launches app based on user usage patterns.

Runtime

~30 seconds (same as legacy background fetch)

Scheduling

func scheduleAppRefresh() {
    let request = BGAppRefreshTaskRequest(identifier: "com.yourapp.refresh")

    // earliestBeginDate = MINIMUM delay (not exact time)
    // System decides actual time based on usage patterns
    request.earliestBeginDate = Date(timeIntervalSinceNow: 15 * 60)

    do {
        try BGTaskScheduler.shared.submit(request)
    } catch BGTaskScheduler.Error.notPermitted {
        // Background App Refresh disabled in Settings
    } catch BGTaskScheduler.Error.tooManyPendingTaskRequests {
        // Too many pending requests for this identifier
    } catch BGTaskScheduler.Error.unavailable {
        // Background tasks not available (Simulator, etc.)
    } catch {
        print("Schedule failed: \(error)")
    }
}

// Schedule when app enters background
func applicationDidEnterBackground(_ application: UIApplication) {
    scheduleAppRefresh()
}

Handler

func handleAppRefresh(task: BGAppRefreshTask) {
    // 1. Set expiration handler FIRST
    task.expirationHandler = { [weak self] in
        self?.currentOperation?.cancel()
    }

    // 2. Schedule NEXT refresh (continuous pattern)
    scheduleAppRefresh()

    // 3. Perform work
    let operation = fetchLatestContentOperation()
    currentOperation = operation

    operation.completionBlock = {
        // 4. Signal completion (REQUIRED)
        task.setTaskCompleted(success: !operation.isCancelled)
    }

    operationQueue.addOperation(operation)
}

BGAppRefreshTaskRequest Properties

PropertyTypeDescription
identifierStringMust match Info.plist
earliestBeginDateDate?Minimum delay before execution

Part 3: BGProcessingTask

Purpose

Deferrable maintenance work (database cleanup, ML training, backups). Runs at system-friendly times, typically overnight when charging.

Runtime

Several minutes (significantly longer than refresh tasks)

Scheduling with Constraints

func scheduleMaintenanceIfNeeded() {
    // Only schedule if work is needed
    guard Date().timeIntervalSince(lastMaintenanceDate) > 7 * 24 * 3600 else {
        return
    }

    let request = BGProcessingTaskRequest(identifier: "com.yourapp.maintenance")

    // CRITICAL for CPU-intensive work
    request.requiresExternalPower = true

    // Optional: Need network for cloud sync
    request.requiresNetworkConnectivity = true

    // Keep within 1 week — longer may be skipped
    // request.earliestBeginDate = ...

    do {
        try BGTaskScheduler.shared.submit(request)
    } catch {
        print("Schedule failed: \(error)")
    }
}

Handler with Progress Checkpointing

func handleMaintenance(task: BGProcessingTask) {
    var shouldContinue = true

    task.expirationHandler = {
        shouldContinue = false
    }

    Task {
        for item in workItems {
            guard shouldContinue else {
                // Expiration called — save progress and exit
                saveProgress()
                break
            }

            await processItem(item)
            saveProgress()  // Checkpoint after each item
        }

        task.setTaskCompleted(success: shouldContinue)
    }
}

BGProcessingTaskRequest Properties

PropertyTypeDefaultDescription
identifierStringMust match Info.plist
earliestBeginDateDate?nilMinimum delay
requiresNetworkConnectivityBoolfalseWait for network
requiresExternalPowerBoolfalseWait for charging

CPU Monitor Disabling

"For the first time ever, we're giving you the ability to turn that off for the duration of your processing task so you can take full advantage of the hardware while the device is plugged in."

When requiresExternalPower = true, CPU Monitor (which normally terminates CPU-heavy background apps) is disabled.


Part 4: BGContinuedProcessingTask (iOS 26+)

Purpose

Continue user-initiated work after app backgrounds, with system UI showing progress. From WWDC 2025-227.

NOT for: Automatic tasks, maintenance, syncing — user must explicitly initiate.

Use Cases

  • Photo/video export
  • Publishing content
  • Updating connected accessories
  • File compression

Info.plist (Wildcard Pattern)

<key>BGTaskSchedulerPermittedIdentifiers</key>
<array>
    <!-- Wildcard for dynamic suffix -->
    <string>com.yourapp.export.*</string>
</array>

Dynamic Registration

Unlike other tasks, register when user initiates action:

func userTappedExportButton() {
    // Register dynamically
    BGTaskScheduler.shared.register(
        forTaskWithIdentifier: "com.yourapp.export.photos"
    ) { task in
        let continuedTask = task as! BGContinuedProcessingTask
        self.handleExport(task: continuedTask)
    }

    // Submit immediately
    submitExportRequest()
}

Submission with Progress UI

func submitExportRequest() {
    let request = BGContinuedProcessingTaskRequest(
        identifier: "com.yourapp.export.photos",
        title: "Exporting Photos",           // Shown in system UI
        subtitle: "0 of 100 photos complete"  // Shown in system UI
    )

    // Strategy: .fail = reject if can't start now; .enqueue = queue (default)
    request.strategy = .fail

    do {
        try BGTaskScheduler.shared.submit(request)
    } catch {
        // Show error — can't run in background now
        showError("Cannot export in background right now")
    }
}

Handler with Mandatory Progress Reporting

func handleExport(task: BGContinuedProcessingTask) {
    var shouldContinue = true

    task.expirationHandler = {
        shouldContinue = false
    }

    // MANDATORY: Report progress
    // Tasks with no progress updates are AUTO-EXPIRED
    task.progress.totalUnitCount = Int64(photos.count)
    task.progress.completedUnitCount = 0

    Task {
        for (index, photo) in photos.enumerated() {
            guard shouldContinue else { break }

            await exportPhoto(photo)

            // Update progress — system displays to user
            task.progress.completedUnitCount = Int64(index + 1)
        }

        task.setTaskCompleted(success: shouldContinue)
    }
}

BGContinuedProcessingTaskRequest Properties

PropertyTypeDescription
identifierStringWith wildcard, can have dynamic suffix
titleStringShown in system progress UI
subtitleStringShown in system progress UI
strategyStrategy.fail or .enqueue (default)

Strategy Options

// .fail — Reject if can't start immediately
request.strategy = .fail

// .enqueue — Queue if can't start (default)
// Task may run later

GPU Access (iOS 26+)

// Check if GPU available for background task
let supportedResources = BGTaskScheduler.shared.supportedResources
if supportedResources.contains(.gpu) {
    // GPU is available
}

Part 5: beginBackgroundTask

Purpose

Finish critical work (~30 seconds) when app transitions to background. For state saving, completing uploads.

Basic Pattern

var backgroundTaskID: UIBackgroundTaskIdentifier = .invalid

func applicationDidEnterBackground(_ application: UIApplication) {
    backgroundTaskID = application.beginBackgroundTask(withName: "Save State") {
        // Expiration handler — clean up immediately
        self.saveProgress()
        application.endBackgroundTask(self.backgroundTaskID)
        self.backgroundTaskID = .invalid
    }

    // Do critical work
    saveEssentialState { [weak self] in
        guard let self = self,
              self.backgroundTaskID != .invalid else { return }

        // End task AS SOON AS work completes
        UIApplication.shared.endBackgroundTask(self.backgroundTaskID)
        self.backgroundTaskID = .invalid
    }
}

Key Points

  • Call endBackgroundTask immediately when done — don't wait for expiration
  • Failing to end may cause system to terminate app
  • ~30 seconds max, not guaranteed
  • Use for finalization, not ongoing work

SwiftUI / SceneDelegate

.onChange(of: scenePhase) { newPhase in
    if newPhase == .background {
        startBackgroundTask()
    }
}

Part 6: Background URLSession

Purpose

Large downloads/uploads that continue even after app termination. Work handed off to system daemon.

Configuration

lazy var backgroundSession: URLSession = {
    let config = URLSessionConfiguration.background(
        withIdentifier: "com.yourapp.downloads"
    )

    // App relaunched when task completes
    config.sessionSendsLaunchEvents = true

    // System chooses optimal time (WiFi, charging)
    config.isDiscretionary = true

    // Timeout for requests (not the download itself)
    config.timeoutIntervalForRequest = 60

    return URLSession(configuration: config, delegate: self, delegateQueue: nil)
}()

Starting Download

func downloadFile(from url: URL) {
    let task = backgroundSession.downloadTask(with: url)
    task.resume()
    // Work continues even if app terminates
}

AppDelegate Handler

var backgroundSessionCompletionHandler: (() -> Void)?

func application(
    _ application: UIApplication,
    handleEventsForBackgroundURLSession identifier: String,
    completionHandler: @escaping () -> Void
) {
    // Store — call after all events processed
    backgroundSessionCompletionHandler = completionHandler
}

URLSessionDelegate Implementation

extension AppDelegate: URLSessionDelegate, URLSessionDownloadDelegate {

    func urlSession(
        _ session: URLSession,
        downloadTask: URLSessionDownloadTask,
        didFinishDownloadingTo location: URL
    ) {
        // MUST move file immediately — temp location deleted after return
        let destination = getDestinationURL(for: downloadTask)
        try? FileManager.default.moveItem(at: location, to: destination)
    }

    func urlSessionDidFinishEvents(forBackgroundURLSession session: URLSession) {
        // All events processed — call stored completion handler
        DispatchQueue.main.async {
            self.backgroundSessionCompletionHandler?()
            self.backgroundSessionCompletionHandler = nil
        }
    }
}

Configuration Properties

PropertyDefaultDescription
sessionSendsLaunchEventsfalseRelaunch app on completion
isDiscretionaryfalseWait for optimal conditions
allowsCellularAccesstrueAllow cellular network
allowsExpensiveNetworkAccesstrueAllow expensive networks
allowsConstrainedNetworkAccesstrueAllow Low Data Mode

Part 7: Testing Background Tasks

LLDB Debugging Commands

Pause app in debugger, then execute:

// Trigger task launch
e -l objc -- (void)[[BGTaskScheduler sharedScheduler] _simulateLaunchForTaskWithIdentifier:@"com.yourapp.refresh"]

// Trigger task expiration
e -l objc -- (void)[[BGTaskScheduler sharedScheduler] _simulateExpirationForTaskWithIdentifier:@"com.yourapp.refresh"]

Testing Workflow

  1. Set breakpoint in task handler
  2. Run app, let it enter background
  3. Pause execution (Debug → Pause)
  4. Execute simulate launch command
  5. Resume — breakpoint should hit
  6. Test expiration handling with simulate expiration

Console Logging

Filter Console.app:

subsystem:com.apple.backgroundtaskscheduler

getPendingTaskRequests

Check what's scheduled:

BGTaskScheduler.shared.getPendingTaskRequests { requests in
    for request in requests {
        print("Pending: \(request.identifier)")
        print("  Earliest: \(request.earliestBeginDate ?? Date())")
    }
}

Part 8: Throttling & System Constraints

The 7 Scheduling Factors

FactorHow to CheckImpact
Critically Low BatteryBattery < ~20%Discretionary work paused
Low Power ModeProcessInfo.isLowPowerModeEnabledLimited activity
App UsageUser opens app frequently?Higher priority
App SwitcherNot swiped away?Swiped = no background
Background App RefreshbackgroundRefreshStatusOff = no BGAppRefresh
System BudgetsMany recent launches?Budget depletes, refills daily
Rate LimitingRequests too frequent?System spaces launches

Checking Constraints

// Low Power Mode
if ProcessInfo.processInfo.isLowPowerModeEnabled {
    // Reduce background work
}

// Listen for changes
NotificationCenter.default.publisher(for: .NSProcessInfoPowerStateDidChange)
    .sink { _ in
        // Adapt behavior
    }

// Background App Refresh status
switch UIApplication.shared.backgroundRefreshStatus {
case .available:
    // Can schedule tasks
case .denied:
    // User disabled — prompt in Settings
case .restricted:
    // MDM or parental controls — cannot enable
@unknown default:
    break
}

Thermal State

switch ProcessInfo.processInfo.thermalState {
case .nominal:
    break  // Normal operation
case .fair:
    // Reduce intensive work
case .serious:
    // Minimize all background activity
case .critical:
    // Stop non-essential work immediately
@unknown default:
    break
}

NotificationCenter.default.publisher(for: ProcessInfo.thermalStateDidChangeNotification)
    .sink { _ in
        // Respond to thermal changes
    }

Part 9: Push Notifications for Background

Silent Push Payload

{
    "aps": {
        "content-available": 1
    },
    "custom-data": "your-payload"
}

APNS Priority

apns-priority: 5   // Discretionary — energy efficient (recommended)
apns-priority: 10  // Immediate — only for time-sensitive

Handler

func application(
    _ application: UIApplication,
    didReceiveRemoteNotification userInfo: [AnyHashable: Any],
    fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void
) {
    guard userInfo["aps"] as? [String: Any] != nil else {
        completionHandler(.noData)
        return
    }

    Task {
        do {
            let hasNewData = try await fetchLatestData()
            completionHandler(hasNewData ? .newData : .noData)
        } catch {
            completionHandler(.failed)
        }
    }
}

Rate Limiting Behavior

"Receiving 14 pushes in a window may result in only 7 launches, maintaining a ~15-minute interval."

Silent pushes are rate-limited. Don't expect launch on every push.


Part 10: SwiftUI Integration

backgroundTask Modifier

@main
struct MyApp: App {
    @Environment(\.scenePhase) var scenePhase

    var body: some Scene {
        WindowGroup {
            ContentView()
        }
        .onChange(of: scenePhase) { newPhase in
            if newPhase == .background {
                scheduleAppRefresh()
            }
        }
        // App refresh handler
        .backgroundTask(.appRefresh("com.yourapp.refresh")) {
            scheduleAppRefresh()  // Schedule next
            await fetchLatestContent()
            // Task completes when closure returns (no setTaskCompleted needed)
        }
        // Background URLSession handler
        .backgroundTask(.urlSession("com.yourapp.downloads")) {
            await processDownloadedFiles()
        }
    }
}

Cancellation with Swift Concurrency

.backgroundTask(.appRefresh("com.yourapp.refresh")) {
    await withTaskCancellationHandler {
        // Normal work
        try await fetchData()
    } onCancel: {
        // Called when task expires
        // Keep lightweight — runs synchronously
    }
}

Background URLSession with SwiftUI

.backgroundTask(.urlSession("com.yourapp.weather")) {
    // Called when background URLSession completes
    // Handle completed downloads
}

Quick Reference

Task Types

TypeRuntimeAPIUse Case
BGAppRefreshTask~30ssubmit(BGAppRefreshTaskRequest)Fresh content
BGProcessingTaskMinutessubmit(BGProcessingTaskRequest)Maintenance
BGContinuedProcessingTaskExtendedsubmit(BGContinuedProcessingTaskRequest)User-initiated
beginBackgroundTask~30sbeginBackgroundTask(withName:)State saving
Background URLSessionAs neededURLSessionConfiguration.backgroundDownloads
Silent Push~30sdidReceiveRemoteNotificationServer trigger

Required Info.plist

<key>BGTaskSchedulerPermittedIdentifiers</key>
<array>
    <string>your.identifiers.here</string>
</array>

<key>UIBackgroundModes</key>
<array>
    <string>fetch</string>      <!-- BGAppRefreshTask -->
    <string>processing</string> <!-- BGProcessingTask -->
</array>

LLDB Commands

// Launch
e -l objc -- (void)[[BGTaskScheduler sharedScheduler] _simulateLaunchForTaskWithIdentifier:@"ID"]

// Expire
e -l objc -- (void)[[BGTaskScheduler sharedScheduler] _simulateExpirationForTaskWithIdentifier:@"ID"]

Resources

WWDC: 2019-707, 2020-10063, 2022-10142, 2023-10170, 2025-227

Docs: /backgroundtasks, /backgroundtasks/bgtaskscheduler, /foundation/urlsessionconfiguration

Skills: axiom-background-processing, axiom-background-processing-diag


Last Updated: 2025-12-31 Platforms: iOS 13+, iOS 26+ (BGContinuedProcessingTask)

适合场景

01

用户想查找某类 Agent Skill 时

02

需要根据任务场景推荐可安装能力包时

03

需要对比不同来源的安装命令和来源信息时

04

需要参考平台分布和安装热度时

能力概览

能力 1

按任务关键词查找相关 Skills

能力 2

展示可复制的安装命令

能力 3

保留来源站点、仓库和原始说明,方便继续核验

能力 4

补充不同宿主或平台的使用分布数据

安装后应在对应宿主中按原始 README 的触发条件使用;具体调用方式请以来源页面和 README 为准。

平台分布

Claude Code

27.91%
按下载量换算370

Codex

23%
按下载量换算305

OpenCode

15.25%
按下载量换算202

Antigravity

12.23%
按下载量换算162

Cursor

7.6%
按下载量换算101

windsurf

3.44%
按下载量换算46

安全审计

暂无安全审计结果可展示。

权限和风险

权限需确认

当前来源未能明确判断权限范围,默认进入异常复核队列。

安装前确认

本站仅展示第三方公开信息,不托管安装包,不提供自动安装或运行环境。安装前应自行审查源码、依赖和命令行为。

来源信息

继续浏览同类 Skills