跳过内容

iOS设置

GitHub

iOS后台处理使用 BGTaskScheduler.

在物理设备上工作之前,应用程序必须在Info.plist中声明后台模式和允许的任务标识符。

Info.plist

添加这些键到 ios/App/App/Info.plist:

<key>UIBackgroundModes</key>
<array>
<string>processing</string>
</array>
<key>BGTaskSchedulerPermittedIdentifiers</key>
<array>
<string>app.capgo.backgroundtask.processing</string>
</array>
终端窗口
npx cap sync ios
  • minimumInterval 映射到 earliestBeginDate.
  • iOS根据电池、网络、使用模式和系统策略决定实际的运行时间。
  • 在模拟器上,后台任务执行不稳定。请在物理设备上测试。
  • 插件在每次任务启动后重新安排下一次后台处理请求。

过期时间

过期时间

使用 addExpirationListener 当 iOS 早期终止任务时,需要清理工作。

const handle = await BackgroundTask.addExpirationListener((event) => {
console.warn('Task expired', event.taskName);
});
await handle.remove();

继续从 iOS 设置

如果您正在使用

iOS 设置 来规划原生插件工作,连接它与 使用 @__CAPGO_KEEP_0__/__CAPGO_KEEP_1__-background-task 为原生能力在使用 @capgo/capacitor-background-task, for the native capability in Using @capgo/capacitor-background-task, Capgo 插件目录 为产品工作流程在 Capgo 插件目录中 Capacitor 插件由 Capgo 为实现细节在 Capacitor 插件由 Capgo 中 添加或更新插件 为实现细节在添加或更新插件中,并 Ionic 企业插件替代品 为产品工作流程在 Ionic 企业插件替代品中