This documentation is available as Markdown for AI agents and LLMs. See the full Markdown index or append .md to any documentation URL.
Expo TaskManager
为可以在后台运行的任务提供支持的库。
expo-task-manager 提供了一个 API,使你能够管理长时间运行的任务,特别是那些可以在你的应用处于后台时运行的任务。该库的一些功能在底层被其他库使用。以下是使用 TaskManager 的 Expo SDK 库列表。
使用 Expo TaskManager 的库
🌐 Libraries using Expo TaskManager
安装
🌐 Installation
If you are installing this in an existing React Native app, make sure to install expo in your project.
信息 你可以在 Expo Go 应用中测试
TaskManager。不过,请查看每个使用TaskManager的 库 的文档,以确认它是否支持在 Expo Go 中进行测试。
配置 iOS
🌐 Configuration
独立应用需要一些额外的配置:在 iOS 上,每个后台功能都需要在你的 Info.plist 文件的 UIBackgroundModes 数组中添加一个特殊的键。
🌐 Standalone apps need some extra configuration: on iOS, each background feature requires a special key in UIBackgroundModes array in your Info.plist file.
阅读更多关于如何在使用 TaskManager 的每个 库 的参考中进行配置的信息。
🌐 Read more about how to configure this in the reference for each of the libraries that use TaskManager.
用法
🌐 Usage
信息 注意:
TaskManager.defineTask必须在模块作用域中调用,而不是在 React 组件内部。上面的示例将它放在屏幕文件的模块作用域中,这对非路由应用是可行的。在 Expo Router 项目中,把它移到一个单独的文件(比如 tasks.ts),然后在根布局(app/_layout.tsx)的顶部导入该文件,这样任务就会在任何导航运行之前被注册。
应用接口
🌐 API
import * as TaskManager from 'expo-task-manager';
No API data file found, sorry!