GithubHelp home page GithubHelp logo

parollon / capacitor-calendar Goto Github PK

View Code? Open in Web Editor NEW

This project forked from fir3st/capacitor-calendar

0.0 0.0 0.0 291 KB

JavaScript 0.50% Ruby 1.87% Objective-C 2.10% Java 66.66% TypeScript 1.96% Swift 26.91%

capacitor-calendar's Introduction

Capacitor Calendar

Perform various actions on the user's calendar:

interface CapacitorCalendar {
  openCalendar(options?: { date: number }): Promise<any>
  createEvent(options: CalendarEventOptions): Promise<any>
  findEvent(options: CalendarEventOptions): Promise<any>
  deleteEvent(options: DeleteEventOptions): Promise<any>
  deleteEventById(options: { id: string }): Promise<any>
  updateEvent(options: CalendarEventOptions): Promise<any>
  getAvailableCalendars(): Promise<any>
}

Usage

For iOS, you must add a NSCalendarsUsageDescription key to Info.plist with a usage description.

This plugin is not yet implemented on web.

Create event simple example

import { Capacitor } from '@capacitor/core';
import { CapacitorCalendar } from 'capacitor-calendar';

async function createEvent(durationHours: number): Promise<void> {
  if (Capacitor.isNativePlatform()) {
    // create calendar event on mobile
    let result: { availableCalendars: { id: string; name: string }[] };
    try {
      // the first time, the user will be prompted to grant permission
      result = await CapacitorCalendar.getAvailableCalendars();
    } catch(e) {}

    if (result?.availableCalendars.length) {
      try {
        const hours = 3600000 * durationHours;
        // use default calendar
        await CapacitorCalendar.createEvent({
          id: 'abc',
          title: 'Launch party',
          location: '1 Infinite Loop, Cupertino CA 95014',
          notes: 'A celebration for all our hard work!',
          startDate: 1677883222055, // start date milliseconds
          endDate: 1677883222055 + hours,
        });
        // show success message here...
      } catch (e) {
        console.error('Error creating calendar event', e);
        // show error message here...
      }
    } else {
      // show error: 'Could not add event to calendar - no calendars found';
    }
  }
}

capacitor-calendar's People

Contributors

fir3st avatar bretislavstepan avatar stonewoodman avatar fllorent0d avatar inorganik avatar srsly4 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.