Need help upgrading to Ionic Framework 4.0? Get assistance with our Enterprise Migration Services EXPLORE NOW

Calendar

Improve this doc

This plugin allows you to add events to the Calendar of the mobile device.

Requires Cordova plugin: cordova-plugin-calendar. For more info, please see the Calendar plugin docs.

Repo: https://github.com/EddyVerbruggen/Calendar-PhoneGap-Plugin

Installation

  1. Install the Cordova and Ionic Native plugins:
    $ ionic cordova plugin add cordova-plugin-calendar
    $ npm install --save @ionic-native/calendar@4
    
  2. Add this plugin to your app's module

Supported platforms

Usage

import { Calendar } from '@ionic-native/calendar';

constructor(private calendar: Calendar) { }


this.calendar.createCalendar('MyCalendar').then(
  (msg) => { console.log(msg); },
  (err) => { console.log(err); }
);

Instance Members

hasReadWritePermission()

This function checks if we have permission to read/write from/to the calendar. The promise will resolve with true when:

If this returns false, you should call the requestReadWritePermission function

Returns: Promise<boolean>

hasReadPermission()

Check if we have read permission

Returns: Promise<boolean>

hasWritePermission()

Check if we have write permission

Returns: Promise<boolean>

requestWritePermission()

Request write permission

Returns: Promise<any>

requestReadPermission()

Request read permission

Returns: Promise<any>

requestReadWritePermission()

Requests read/write permissions

Returns: Promise<any>

createCalendar(nameOrOptions)

Create a calendar. (iOS only)

Param Type Details
nameOrOptions string|NameOrOptions

either a string name or a options object. If string, provide the calendar name. IF an object, provide a calendar name as a string and a calendar color in hex format as a string

Returns: Promise<any> Returns a Promise

deleteCalendar(name)

Delete a calendar. (iOS only)

Param Type Details
name string

Name of the calendar to delete.

Returns: Promise<any> Returns a Promise

getCalendarOptions()

Returns the default calendar options.

Returns: CalendarOptions Returns an object with the default calendar options

getCreateCalendarOptions()

Returns options for a custom calender with specific color

Returns: NameOrOptions Returns an object with the default options

createEvent(title, location, notes, startDate, endDate)

Silently create an event.

Param Type Details
title string

The event titleOptional

location string

The event locationOptional

notes string

The event notesOptional

startDate Date

The event start dateOptional

endDate Date

The event end dateOptional

Returns: Promise<any> Returns a Promise

createEventWithOptions(title, location, notes, startDate, endDate, options)

Silently create an event with additional options.

Param Type Details
title string

The event titleOptional

location string

The event locationOptional

notes string

The event notesOptional

startDate Date

The event start dateOptional

endDate Date

The event end dateOptional

options CalendarOptions

Additional options, see getCalendarOptionsOptional

Returns: Promise<any> Returns a Promise

createEventInteractively(title, location, notes, startDate, endDate)

Interactively create an event.

Param Type Details
title string

The event titleOptional

location string

The event locationOptional

notes string

The event notesOptional

startDate Date

The event start dateOptional

endDate Date

The event end dateOptional

Returns: Promise<any> Returns a Promise

createEventInteractivelyWithOptions(title, location, notes, startDate, endDate, options)

Interactively create an event with additional options.

Param Type Details
title string

The event titleOptional

location string

The event locationOptional

notes string

The event notesOptional

startDate Date

The event start dateOptional

endDate Date

The event end dateOptional

options CalendarOptions

Additional options, see getCalendarOptionsOptional

Returns: Promise<any>

findEvent(title, location, notes, startDate, endDate)

Find an event.

Param Type Details
title string

The event titleOptional

location string

The event locationOptional

notes string

The event notesOptional

startDate Date

The event start dateOptional

endDate Date

The event end dateOptional

Returns: Promise<any>

findEventWithOptions(title, location, notes, startDate, endDate, options)

Find an event with additional options.

Param Type Details
title string

The event titleOptional

location string

The event locationOptional

notes string

The event notesOptional

startDate Date

The event start dateOptional

endDate Date

The event end dateOptional

options CalendarOptions

Additional options, see getCalendarOptionsOptional

Returns: Promise<any> Returns a Promise that resolves with the event, or rejects with an error.

listEventsInRange(startDate, endDate)

Platforms:Android 

Find a list of events within the specified date range. (Android only)

Param Type Details
startDate Date

The start dateOptional

endDate Date

The end dateOptional

Returns: Promise<any> Returns a Promise that resolves with the list of events, or rejects with an error.

listCalendars()

Get a list of all calendars.

Returns: Promise<any> A Promise that resolves with the list of calendars, or rejects with an error.

findAllEventsInNamedCalendar()

Platforms:iOS 

Get a list of all future events in the specified calendar. (iOS only)

Returns: Promise<any> Returns a Promise that resolves with the list of events, or rejects with an error.

modifyEvent(title, location, notes, startDate, endDate, newTitle, newLocation, newNotes, newStartDate, newEndDate)

Platforms:iOS 

Modify an event. (iOS only)

Param Type Details
title string

The event titleOptional

location string

The event locationOptional

notes string

The event notesOptional

startDate Date

The event start dateOptional

endDate Date

The event end dateOptional

newTitle string

The new event titleOptional

newLocation string

The new event locationOptional

newNotes string

The new event notesOptional

newStartDate Date

The new event start dateOptional

newEndDate Date

The new event end dateOptional

Returns: Returns a Promise

modifyEventWithOptions(title, location, notes, startDate, endDate, newTitle, newLocation, newNotes, newStartDate, newEndDate, filterOptions, newOptions)

Platforms:iOS 

Modify an event with additional options. (iOS only)

Param Type Details
title string

The event titleOptional

location string

The event locationOptional

notes string

The event notesOptional

startDate Date

The event start dateOptional

endDate Date

The event end dateOptional

newTitle string

The new event titleOptional

newLocation string

The new event locationOptional

newNotes string

The new event notesOptional

newStartDate Date

The new event start dateOptional

newEndDate Date

The new event end dateOptional

filterOptions CalendarOptions

Event Options, see getCalendarOptionsOptional

newOptions CalendarOptions

New event options, see getCalendarOptionsOptional

Returns: Returns a Promise

deleteEvent(title, location, notes, startDate, endDate)

Delete an event.

Param Type Details
title string

The event titleOptional

location string

The event locationOptional

notes string

The event notesOptional

startDate Date

The event start dateOptional

endDate Date

The event end dateOptional

Returns: Returns a Promise

deleteEventFromNamedCalendar(title, location, notes, startDate, endDate, calendarName)

Platforms:iOS 

Delete an event from the specified Calendar. (iOS only)

Param Type Details
title string

The event titleOptional

location string

The event locationOptional

notes string

The event notesOptional

startDate Date

The event start dateOptional

endDate Date

The event end dateOptional

calendarName string

Returns: Returns a Promise

openCalendar(date)

Open the calendar at the specified date.

Param Type Details
date Date

The date you want to open the calendar on

Returns: Promise<any> Promise returns a promise

CalendarOptions

Param Type Details
id string

Id

(optional)
firstReminderMinutes number (optional)
secondReminderMinutes number (optional)
recurrence string

Recurrence. Can be set to daily, weekly, monthly or yearly

(optional)
recurrenceInterval number

Recurrence interval. Valid only when recurrence option is set.

(optional)
recurrenceEndDate Date

Recurrence end date. Valid only when recurrence option is set.

(optional)
calendarName string

Calendar name. Ths is supported by iOS only.

(optional)
calendarId number

Calendar id

(optional)
url string

URL

(optional)

NameOrOptions

Param Type Details
calendarName string

Calendar name

(optional)
calendarColor string

Calendar color as a HEX string

(optional)

API

Native

General