A React Native module to help access and save events to iOS and Android calendars.
This package assumes that you already have a React Native project or are familiar with React Native. If not, checkout the official documentation for more details about getting started with React Native.
The following is required for the package to work properly.
Install the react-native-calendar-util
library with native code.
npm install --save github:kkhung0829/react-native-calendar-util
Since this package contains native code, you will need to include the code as a library. The React Native documentation on "Linking Libraries" also provides some details for this process.
- Automatic linking
react-native link
- Manual linking
Sometimes "automatic linking" is not sufficient or is not properly including the library. Fortunately, the React Native docs on "Manual Linking" serves a helpful guide (with pictures) in the process.
Setting up privacy usage descriptions may also be require depending on which iOS version is supported. This involves updating the Property List, Info.plist, with the corresponding key for the EKEventStore api. Info.plist reference
For updating the Info.plist key/value via XCode, add a Privacy - Calendars Usage Description key with a usage description as the value. Resulting change to Info.plist should look something like:
<key>NSCalendarsUsageDescription</key>
<string>This app requires access to the calendar</string>
Note that for iOS react-native link will not automatically add the required privacy usage description to your Info.plist file, you'll need to do that manually.
The following API allows for interacting with both iOS and Android device calendars. See the full list of available event fields.
import RNCalendarUtil from 'react-native-calendar-util';
Get calendar authorization status.
RNCalendarUtil.authorizationStatus()
Returns: Promise
- fulfilled: Boolean
- rejected: Error
Request calendar authorization. Authorization must be granted before accessing calendar events.
Android note: This is only necessary for targeted SDK of 23 and higher.
RNCalendarUtil.authorizeEventStore()
Returns: Promise
- fulfilled: Boolean
- rejected: Error
List all the calendars on the device.
RNCalendarUtil.listCalendars()
Returns: Promise
- fulfilled: Array - A list of known calendars on the device
- rejected: Error
Create calendars on the device.
RNCalendarUtil.createCalendar(name)
Returns: Promise
- fulfilled: The new calendar id
- rejected: Error
Delete calendars on the device.
RNCalendarUtil.deleteCalendar(name)
Returns: Promise
- fulfilled: Nothing
- rejected: Error
Returns the default calendar options.
RNCalendarUtil.getCalendarOptions()
Returns: An object with the default calendar options
Create an event.
RNCalendarUtil.createEvent(title, location, notes, startTimeMS, endTimeMS)
Arguments:
- title: The event title
- location: The event location
- notes: The event notes
- startTimeMS: The event start date in numeric value (date.getTime())
- endTimeMS: The event end date in numeric value (date.getTime())
Returns: Promise
- fulfilled: The new event id.
- rejected: Error
Create an event.
RNCalendarUtil.createEventWithOptions(title, location, notes, startTimeMS, endTimeMS, options)
Arguments:
- title: The event title
- location: The event location
- notes: The event notes
- startTimeMS: The event start date in numeric value (date.getTime())
- endTimeMS: The event end date in numeric value (date.getTime())
- options: Additional options obtained by getCalendarOptions().
Returns: Promise
- fulfilled: The new event id.
- rejected: Error