All posts

· 6 min read

How to Migrate the Capacitor Calendar Plugin to Capacitor 9

Upgrade the Capacitor Calendar plugin for Capacitor 9: new iOS and Android minimums, renamed result keys with before and after code, and a migration checklist.

Version 9 of Capacitor Calendar is out, and it brings the plugin to Capacitor 9. For most Ionic and Capacitor apps, the upgrade is small: new minimum platform versions, and clearer result keys for eight methods.

This guide walks you through the migration step by step, with before and after code for every breaking change and a checklist at the end. It covers the move from version 8 of the plugin, which supports Capacitor 8, to version 9.

What Changes in Version 9

  • Capacitor 9 is required. The minimum targets are now iOS 16 and Android API level 26.
  • Eight methods resolve new keys. For example, listCalendars() resolves { calendars } instead of { result }. Your TypeScript build shows you each place to fix.
  • Every result has a named type, such as ListCalendarsResult or CheckPermissionResult.
  • Android resolves null for empty values, like iOS already did. Before, the key was missing.

Apart from these changes, the API stays the same. Events, reminders, permission requests and the web helpers work as before.

Step 1: Update Your App to Capacitor 9

The plugin needs @capacitor/core 9 or newer. Update your app first with the official Capacitor 9 update guide. Then check that the native projects meet the new minimums:

SettingVersion 8 of the pluginVersion 9 of the plugin
Capacitor89
iOS deployment targetiOS 15iOS 16
Android minSdkVersion2426
Android compileSdkVersion3637

On Android, the values are in android/variables.gradle of a Capacitor project:

ext {
  minSdkVersion = 26
  compileSdkVersion = 37
  // Keep the other values from the Capacitor 9 update guide.
}

On iOS, set the deployment target of the App target in Xcode to 16.0 or higher. If you use CocoaPods, also set platform :ios, '16.0' in ios/App/Podfile.

If Your App Uses Swift Package Manager

The plugin now depends on the https://github.com/ionic-team/capacitor.git package instead of capacitor-swift-pm, and it no longer needs the Cordova product. npx cap sync updates the package setup for you. If Xcode still shows an old package, use File > Packages > Reset Package Caches.

Step 2: Install the New Plugin Version

Install the latest release and sync the native projects:

npm install @ebarooni/capacitor-calendar@latest
npx cap sync

Not ready for Capacitor 9 yet? Version 8 stays available under its own npm tag. Pin it, so that a later install does not pull in version 9 by accident:

npm install @ebarooni/capacitor-calendar@latest-8

Step 3: Read the New Result Keys

This is the main breaking change. Before, many methods wrapped their value in a generic result key. Now, eight of them resolve a key that says what it holds, or put the values at the top level:

MethodBeforeAfter
listCalendars()resultcalendars
getDefaultCalendar()resultcalendar
checkAllPermissions()result.readCalendarreadCalendar
requestAllPermissions()result.readCalendarreadCalendar
deleteEventsById()result.deleteddeleted
deleteRemindersById()result.deleteddeleted
getRemindersLists() (iOS)resultremindersLists
getDefaultRemindersList() (iOS)resultremindersList

In the table, a dot means a key inside result. Keys like writeCalendar and failed move the same way.

In code, the change usually touches one line per call:

// Before
const { result: calendars } = await CapacitorCalendar.listCalendars();
const { result: defaultCalendar } =
  await CapacitorCalendar.getDefaultCalendar();
const { result: permissions } = await CapacitorCalendar.checkAllPermissions();
const { result: deletion } = await CapacitorCalendar.deleteEventsById({ ids });
console.log(deletion.deleted, deletion.failed);

// After
const { calendars } = await CapacitorCalendar.listCalendars();
const { calendar: defaultCalendar } =
  await CapacitorCalendar.getDefaultCalendar();
const permissions = await CapacitorCalendar.checkAllPermissions();
const { deleted, failed } = await CapacitorCalendar.deleteEventsById({ ids });
console.log(deleted, failed);

With TypeScript, run your build or type check. The compiler lists every call that still reads result from these eight methods. In a JavaScript project, search for the method names instead:

grep -rnE "(listCalendars|getDefaultCalendar|checkAllPermissions|requestAllPermissions|deleteEventsById|deleteRemindersById|getRemindersLists|getDefaultRemindersList)\(" src

Change only these eight methods. All other methods keep their result key. For example, requestFullCalendarAccess() still resolves { result: 'granted' }, and listEventsInRange() still resolves { result: events }.

Step 4: Update Your Type Imports

Every method that resolves a value now has a named *Result interface, for example CheckPermissionResult, RequestFullCalendarAccessResult or GetDefaultCalendarResult. The interface describes the whole resolved value. For most methods, only the type name is new and the data stays the same.

Look closer if you used CheckAllPermissionsResult, RequestAllPermissionsResult, DeleteEventsByIdResult or DeleteRemindersByIdResult in version 8. These names used to describe the value inside result. Now they describe the whole result, so the unwrapping step goes away:

import type { CheckAllPermissionsResult } from '@ebarooni/capacitor-calendar';

// Before
const permissions: CheckAllPermissionsResult = (
  await CapacitorCalendar.checkAllPermissions()
).result;

// After
const permissions: CheckAllPermissionsResult =
  await CapacitorCalendar.checkAllPermissions();

Step 5: Check for null on Android

This change does not break your build, so it is easy to miss. On Android, empty values are now null, the same as on iOS. Before, the key was missing, so the value was undefined. This applies to:

  • calendar from getDefaultCalendar() when the device has no default calendar
  • empty calendar fields, such as colorName, type or source
  • empty event fields from listEventsInRange(), getEventById() and the calendarChanged listener, such as location, url, description and the attendee fields
  • result from modifyEventWithPrompt(), ics from createEvent(), and ics and id from createEventWithPrompt()

Checks with === undefined or 'key' in object now give a different answer on Android. Use == null or ??, which work on both platforms:

// Before: true on Android only when the key was missing
if (event.location === undefined) {
  hideLocation();
}

// After: true for null and undefined, on Android and iOS
if (event.location == null) {
  hideLocation();
}

const place = event.location ?? 'No location';

Migration Checklist

  • The app runs on Capacitor 9.
  • The iOS deployment target is 16.0 or higher.
  • Android uses minSdkVersion 26 and compileSdkVersion 37.
  • @ebarooni/capacitor-calendar@latest is installed and npx cap sync ran.
  • The eight methods read their new keys, and the build has no type errors.
  • Type imports of the permission and delete results no longer unwrap result.
  • Checks for empty values use == null or ??, not === undefined.
  • You tested permissions, listing and the default calendar on a real iOS and Android device.

Where to Go Next

The plugin repository has the complete list of changes for each release: