This documentation is available as Markdown for AI agents and LLMs. See the full Markdown index or append .md to any documentation URL.
Expo 日历(传统)
一个库,提供用于与设备的系统日历、事件、提醒和关联记录进行交互的 API。
重要 Calendar API 的
legacy版本包含在expo-calendar库中。它可以与基于类的expo-calendarAPI 一起使用,该 API 从根导出。要使用旧版 API,请从expo-calendar/legacy导入。
expo-calendar 提供了用于与设备系统日历、事件、提醒及相关记录进行交互的 API。
此外,它提供了启动系统提供的日历界面的方法,以便用户查看或编辑事件。在安卓上,这些方法使用 Intent 启动系统日历应用。在 iOS 上,它们会以模态形式展示EKEventViewController或EKEventEditViewController。
🌐 Additionally, it provides methods to launch the system-provided calendar UI to allow user view or edit events. On Android, these methods start the system calendar app using an Intent. On iOS, they present either EKEventViewController or EKEventEditViewController as a modal.
安装
🌐 Installation
If you are installing this in an existing React Native app, make sure to install expo in your project.
应用配置中的配置
🌐 Configuration in app config
如果你在项目中使用配置插件(连续原生生成 (CNG)),可以使用其内置的 配置插件 来配置 expo-calendar。该插件允许你配置无法在运行时设置并且需要构建新的应用二进制文件才能生效的各种属性。如果你的应用不使用 CNG,那么你需要手动配置该库。
🌐 You can configure expo-calendar using its built-in config plugin if you use config plugins in your project (Continuous Native Generation (CNG)). The plugin allows you to configure various properties that cannot be set at runtime and require building a new app binary to take effect. If your app does not use CNG, then you'll need to manually configure the library.
Example app.json with config plugin
Configurable properties
Are you using this library in an existing React Native app?
如果你没有使用连续原生生成(CNG)(而是手动使用原生 Android 和 iOS 项目),那么你需要在原生项目中配置以下权限:
🌐 If you're not using Continuous Native Generation (CNG) (you're using native android and ios projects manually), then you need to configure following permissions in your native projects:
-
对于 Android,在项目的 android/app/src/main/AndroidManifest.xml 中添加
android.permission.READ_CALENDAR和android.permission.WRITE_CALENDAR权限:<uses-permission android:name="android.permission.READ_CALENDAR" /> <uses-permission android:name="android.permission.WRITE_CALENDAR" /> -
对于 iOS,将
NSCalendarsUsageDescription和NSRemindersUsageDescription添加到你项目的 ios/[app]/Info.plist 中:<key>NSCalendarsUsageDescription</key> <string>Allow $(PRODUCT_NAME) to access your calendar</string> <key>NSRemindersUsageDescription</key> <string>Allow $(PRODUCT_NAME) to access your reminders</string>
用法
🌐 Usage
应用接口
🌐 API
import * as Calendar from 'expo-calendar/legacy';
No API data file found, sorry!
权限
🌐 Permissions
安卓
🌐 Android
如果你只打算使用系统提供的日历界面,则无需请求任何权限。
🌐 If you only intend to use the system-provided calendar UI, you don't need to request any permissions.
否则,你必须将以下权限添加到 app.json 的 expo.android.permissions 数组中。
🌐 Otherwise, you must add the following permissions to your app.json inside the expo.android.permissions array.
iOS
如果你只打算使用系统提供的日历界面通过 createEventInCalendarAsync 创建事件,则无需请求权限。
🌐 If you only intend to create events using system-provided calendar UI with createEventInCalendarAsync, you don't need to request permissions.
该库使用以下用法描述键:
🌐 The following usage description keys are used by this library: