使用标准的 iOS/Android 对话框在 React Native 中创建、查看或编辑事件
使用标准的 iOS/Android 对话框在 React Native 中创建、查看或编辑事件
[!IMPORTANT] This package has been deprecated in favor of
expo-calendarwhich provides the features of this package (and more) and does so in a better way. Please use the package provided by Expo. Thank you.
This package alows you to start an activity (Android) or show a modal window (iOS) for adding, viewing or editing events in device's calendar. Through a promise, you can find out if a new event was added and get its ID, or if it was removed.
For managing calendar events without the UI for user to interact with, see react-native-calendar-events.
npm install react-native-add-calendar-event --save
or
yarn add react-native-add-calendar-event
You'll also need to install and setup react-native-permissions, or similar, to request calendar permissions for your app.
This package is not available in the Expo Go app. Learn how you can use it with custom dev clients.
(only RN = 0.60) run pod install in the ios folder
add NSCalendarsWriteOnlyAccessUsageDescription or NSCalendarsFullAccessUsageDescription (for edit/view access) to your Info.plist file. The string value associated with the key will be used when asking user for calendar permission.
rebuild your project
iOS note for RN {
if (result !== Permissions.RESULTS.GRANTED) {
throw new Error(No permission: ${result});
}
return AddCalendarEvent.presentEventCreatingDialog(eventConfig)
})
.then((eventInfo: { calendarItemIdentifier: string, eventIdentifier: string }) => {
// handle success - receives an object with calendarItemIdentifier and eventIdentifier keys, both of type string.
// These are two different identifiers on iOS.
// On Android, where they are both equal and represent the event id, also strings.
// when { action: 'CANCELED' } is returned, the dialog was dismissed
console.warn(JSON.stringify(eventInfo));
})
.catch((error: string) => {
// handle error such as when user rejected permissions
console.warn(error);
});
…navigationBarIOS: { tintColor: string, barTintColor: string, backgroundColor: string, translucent: boolean, titleColor: string, }
…include ':react-native-add-calendar-event'
project(':react-native-add-calendar-event').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-add-calendar-event/android')
```
android/app/build.gradle: compile project(':react-native-add-calendar-event')暂无开放 Issues,或尚未同步最近议题。