Giter VIP home page Giter VIP logo

nativescript-calendar's Introduction

NativeScript Calendar Plugin

Build Status NPM version Downloads Twitter Follow

The Calendar plugin allows you to manipulate events in the user's native Calendar. You can find, create and delete events in either the default or a custom calendar.

If you're looking for an awesome in-app UI for the native calendar, then check this out.

Installation

From the command prompt go to your app's root folder and execute:

NativeScript 7

tns plugin add nativescript-calendar

NativeScript 6

tns plugin add [email protected]

iOS runtime permission reason

You probably have seen a permission popup like this before (this plugin will trigger one as well, automatically):

iOS 10+ requires not only this popup, but also a reason. In this case it's "Custom message from App_Resources".

You can provide your own reason for accessing the calendar by adding something like this to app/App_Resources/ios/Info.plist:

  <key>NSCalendarsUsageDescription</key>
  <string>My reason justifying fooling around with your calendar</string>

To not crash your app in case you forgot to provide the reason this plugin adds an empty reason to the .plist during build. This value gets overridden by anything you specified yourself. You're welcome.

TypeScript Usage

Of course you can use this plugin with TypeScript, just import the plugin and use the functions summed up below like this:

import * as Calendar from "nativescript-calendar";

// example for listCalendars:
Calendar.listCalendars().then(/* .. */);

Usage

If you want a quickstart, clone our demo app.

createEvent

  var Calendar = require("nativescript-calendar");

  // Only the `title`, `startDate` and `endDate` are mandatory, so this would suffice:
  var options = {
    title: 'Get groceries',
    // Make sure these are valid JavaScript Date objects.
    // In this case we schedule an Event for now + 1 hour, lasting 1 hour.
    startDate: new Date(new Date().getTime() + (60*60*1000)),
    endDate: new Date(new Date().getTime() + (2*60*60*1000))
  };

  // You can however add lots of properties to enrich the Event:
  options.location = 'The shop';
  options.notes = 'This event has reminders';

  // iOS has a separate 'url' field, but on Android the plugin appends this to the 'notes' field.
  options.url = 'http://my.shoppinglist.com';

  // You can also override the default reminder(s) of the Calendar (in minutes):
  options.reminders = {
    first: 30,
    second: 10
  };

  // You can make this Event recurring (this one repeats every other day for 10 days):
  options.recurrence = {
    frequency: "daily", // daily | weekly | monthly | yearly
    interval: 2, // once every 2 days
    endDate: new Date(new Date().getTime() + (10*24*60*60*1000)) // 10 days
  };

  // Want to use a custom calendar for your app? Pass in the 'name'.
  // If the name doesn't yet exist the plugin will create it for you.
  options.calendar = {
    name: "NativeScript Cal",
    // the color, in this case red
    color: "#FF0000",
    // Can be used on Android to group the calendars. Examples: Your app name, or an emailaddress
    accountName: "My App Name"
  };

  Calendar.createEvent(options).then(
      function(createdId) {
        console.log("Created Event with ID: " + createdId);
      },
      function(error) {
        console.log("Error creating an Event: " + error);
      }
  );

If you want an 'all day event', make sure you set the dates to midnight like this:

  var d = new Date();
  d.setHours(0);
  d.setMinutes(0);
  d.setSeconds(0);

  // this will create an 'all day event' for tomorrow
  var startDate = new Date(d.getTime() + (24*60*60*1000));
  var endDate = new Date(d.getTime() + (2*24*60*60*1000));
  // .. now use these properties in the options object

findEvents

  var options = {
    // when searching, dates are mandatory - the event must be within this interval
    startDate: new Date(new Date().getTime() - (50*24*60*60*1000)),
    endDate: new Date(new Date().getTime() + (50*24*60*60*1000))
  };

  // if you know the Event ID, set it here:
  options.id = '123456';

  // you can optionally pass in a few other properties, any event containing these will be returned:
  options.title = 'groceries';
  options.location = 'foo';
  options.notes = 'bar'; // iOS only

  Calendar.findEvents(options).then(
      function(events) {
        console.log(JSON.stringify(events));
      },
      function(error) {
        console.log("Error finding Events: " + error);
      }
  );

The returned 'events' object is an array of JSON events with these properties:

id
title
location
notes
url
startDate
endDate
allDay
calendar {id, name}
reminders {minutes}
recurrence {frequency, interval, endDate}
attendees {name, email, url, status, role, type}

deleteEvents

Usage is largely the same as findEvents, only the result is a bit different ;)

  var options = {
    // when searching, dates are mandatory - the event must be within this interval
    startDate: new Date(new Date().getTime() - (50*24*60*60*1000)),
    endDate: new Date(new Date().getTime() + (50*24*60*60*1000))
  };

  // if you know the Event ID, set it here:
  options.id = '123456';

  // you can optionally pass in a few other properties, any event containing these will be deleted:
  options.title = 'groceries'; // events _including_ this string will be included in the selection
  options.location = 'foo';
  options.notes = 'bar'; // iOS only

  Calendar.deleteEvents(options).then(
      function(deletedEventIds) {
        console.log(JSON.stringify(deletedEventIds));
      },
      function(error) {
        console.log("Error deleting Events: " + error);
      }
  )

listCalendars

  Calendar.listCalendars().then(
      function(calendars) {
        // a JSON array of Calendar objects is returned, each with an 'id' and 'name'
        console.log("Found these Calendars on the device: " + JSON.stringify(calendars));
      },
      function(error) {
        console.log("Error while listing Calendars: " + error);
      }
  )

deleteCalendar

TypeScript
import * as Calendar from "nativescript-calendar";

Calendar.deleteCalendar({
  name: "My Calendar name"
}).then(id => {
  // id is null if nothing was deleted
  console.log(`Deleted Calendar with id ${id}`);
});

Breaking changes in 2.0.0

See CHANGELOG.md.

nativescript-calendar's People

Contributors

bzaruk avatar eddyverbruggen avatar rowdyrabouw avatar slejnej avatar wendt88 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

nativescript-calendar's Issues

Cannot delete existing entries in iOS

PROBLEM: Cannot delete existing entries in iOS.

Getting the following error:

Error getting calendar item with UUID (null): Error Domain=EKCADErrorDomain Code=1010 "(null)"

FIX:

After reviewing your code in calendar.ios.js - the problem seems to be in line #370

if (settings.id !== null) {

If settings.id is undefined, the above expression evaluates to true and the problem occurs.

Same expression in findEvents() .

I suppose one can set id property explicitly to null and it'll work - but no where in the docs does it say it needs to be set and most peeps would just leave it undefined.

Other issues:

I also noticed in index.d.js in your definition of DeleteEventsOptions - there's no definition of "name" property (for the calendar). That is for setting a calendar.

Also in the same file, line #47 url?: URL - URL is undefined in both ios and android.

How to use this in ng nativescript

I try to import that by it fails in typescript compilation. With below error.

error TS2307: Cannot find module 'nativescript-calendar'.

Import code

import Calendar = require("nativescript-calendar");

[Android] Not setting options.url adds undefined to description

Hi,

I'm using typescript with angular 2 and your plugin in version 1.0.6 :)
When I'm not seting the options.url to null, the created calendar event get's an "undefined" added.

The JSON generated by my program is:
JS: createEvent={"title":"SomeTitle","startDate":"2015-11-03T15:30:00.000Z","endDate":"2015-11-03T17:06:00.000Z","calendar":{"name":"Dummy"},"notes":"SomeText","location":"SomeLocation"}

and this results in "SomeText undefined".
undefined

When setting url to null:
JS: createEvent={"title":"SomeTitle","startDate":"2015-11-03T15:30:00.000Z","endDate":"2015-11-03T17:06:00.000Z","calendar":{"name":"Dummy"},"notes":"SomeText","location":"SomeLocation","url":null}
it works fine.

I would like to not have to set url manually to null.

Returning E-Mail for Attendees

Hi @EddyVerbruggen,

I'd like to read the e-mail address of an attendee. After playing around a little, I've found that you could get it easily via ekParticipant.URL.resourceSpecifier in line https://github.com/EddyVerbruggen/nativescript-calendar/blob/master/src/calendar.ios.ts#L167 . The code could look like this:

attendees.push({
    name: ekParticipant.name,
    email: ekParticipant.URL.resourceSpecifier,
    url: ekParticipant.URL,
    status: attendeeStatuses[ekParticipant.participantStatus],
    role: attendeeRoles[ekParticipant.participantRole],
    type: attendeeTypes[ekParticipant.participantType]
});

As you haven't published any contribution guidelines I wasn't sure whether you'd like to receive PRs or not. Let me know if so, otherwise it'd be awesome if you could add the e-mail field. It'd be great if it could be optional in the TypeScript type https://github.com/EddyVerbruggen/nativescript-calendar/blob/master/src/index.d.ts#L183.

Thanks a bunch

Assertion failure

Everything works great until I try and add an event to a new calendar, at which point I get:

*** Assertion failure in +[EKCalendar calendarForEntityType:eventStore:], /BuildRoot/Library/Caches/com.apple.xbs/Sources/EventKit_Sim/EventKit-672/EventKit/iOS/src/EKCalendar.m:52

Here is my code:

  toggleFavorite(e) {

      var options = {
          calendar: {name: "AAPA 2017"}, \\ Works fine until I add this line
          title: this.session.title,
          startDate: new Date(new Date().getTime() + (60 * 60 * 1000)),
          endDate: new Date(new Date().getTime() + (2 * 60 * 60 * 1000)),
          location: this.session.location,
          reminders: {first: 10},
          id: "0"
      };

      let a = this.session
      if (!this.session.favorite) {

          Calendar.createEvent(options).then(
              function(createdId) {
                  console.log("Created Event with ID: " + createdId);
                  a.cal_id = createdId;
                  a.favorite = true;
              },
              function(error) {
                  console.log("Error creating an Event: " + error);
              }
          );

      } else {

          options.id = this.session.cal_id

          Calendar.deleteEvents(options).then(
              function(deletedEventIds) {
                  console.log('Event deleted');
                  a.cal_id = "0";
                  a.favorite = false;
              },
              function(error) {
                  console.log("Error deleting Events: " + error);
              }
          )
      }
  }

Notes not visible in calendar app

I created a new event with a note - but there doesn't seem to be a way to view these notes in the calendar app.

I did an export of the event (as text) and the info was there - so it's being saved by the plug-in properly.

I understand this isn't really a plug-in issue - but how does one view the saved notes.

I tried this with the default google calendar as well as samsung calendar.

I'd like to save some text (w/ new-line) for each event. I tried saving as title but that doesn't allow new-lines.

Calendar sound alert

Hello Eddy, first thanks for creating this plugin.

Please, is there a way to add sound to the calendar event created? Thanks.

endDate in findEvents results not always correct

The endDate in results from findEvents is sometimes returned as 1970-01-01T00:00:00.000Z, even if allDay is false. In other cases the date is correct. The events are in a google calendar and were not created via your plugin. This is on Android.

App crash when denying permissions

  • Platform: Android 6 / 7 / etc.
  • Plugin version: 1.2.2
  • NS CLI / Core Modules Version: 3.3.0
  • Using NS + Angular in this case.

Hi, this plugin seems to be causing apps to crash when denying (any) permissions on Android.

For example:

  1. Open an app which includes this plugin and any other plugin (camera plugin, geolocation, etc.).
  2. At any moment, request permissions for geolocation (or any other feature).
  3. Deny the permission(s).
  4. The app will (most probably) crash.

The same if you deny permissions for any plugin (being it the calendar plugin, camera, or whatever).

It's not necessary to try to perform any other actions (for example to try to take a picture), apps seems to crash simply by denying any permission(s).

It seems that by just having

import * as Calendar from 'nativescript-calendar';

in some component and, for example

Calendar.createEvent(options)

the app will crash.

This comment points to where the problem could be NativeScript/nativescript-geolocation#94 (comment)

Specifically this line seems to be causing the problem by trying to handle all permission requests

application.android.on(application.AndroidApplication.activityRequestPermissionsEvent, function (args) {

Other than this, the plugin seems to work fine.

Read and Write Permission Error in Android 8

Hi Guys, I need a big help here please, i'm facing an error that only seems to happen in Android 8,
when the application request for permission and i granted, the app crashes, then I open again the application, and try to create an Event with the createEvent method, and get the error i posted below.

i have in the manifest file this permissions too.

<uses-permission android:name="android.permission.READ_CALENDAR"/> <uses-permission android:name="android.permission.WRITE_CALENDAR"/>

I any other Android version i have tested work perfect.

I will thankful for any help you can provide me!

JS: Error in Calendar.createEvent: Error: java.lang.SecurityException: Permission Denial: reading com.android.providers.calendar.CalendarProvider2 uri content://com.android.calendar/calendars from pid=2278, uid=10068 requires android.permission.READ_CALENDAR, or grantUriPermission() JS: android.os.Parcel.readException(Parcel.java:1942) JS: android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:183) JS: android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:135) JS: android.content.ContentProviderProxy.query(ContentProviderNative.java:418) JS: android.content.ContentResolver.query(ContentResolver.java:754) JS: android.content.ContentResolver.query(ContentResolver.java:704) JS: android.content.ContentResolver.query(ContentResolver.java:662) JS: com.tns.Runtime.callJSMethodNative(Native Method) JS: com.tns.Runtime.dispatchCallJSMethodNative(Runtime.java:1116) JS: com.tns.Runtime.callJSMethodImpl(Runtime.java:996) JS: com.tns.Runtime.callJSMethod(Runtime.java:983) JS: com.tns.Run... JS: Error creating the event Error: java.lang.SecurityException: Permission Denial: reading com.android.providers.calendar.CalendarProvider2 uri content://com.android.calendar/calendars from pid=2278, uid=10068 requires android.permission.READ_CALENDAR, or grantUriPermission() JS: android.os.Parcel.readException(Parcel.java:1942) JS: android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:183) JS: android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:135) JS: android.content.ContentProviderProxy.query(ContentProviderNative.java:418) JS: android.content.ContentResolver.query(ContentResolver.java:754) JS: android.content.ContentResolver.query(ContentResolver.java:704) JS: android.content.ContentResolver.query(ContentResolver.java:662) JS: com.tns.Runtime.callJSMethodNative(Native Method) JS: com.tns.Runtime.dispatchCallJSMethodNative(Runtime.java:1116) JS: com.tns.Runtime.callJSMethodImpl(Runtime.java:996) JS: com.tns.Runtime.callJSMethod(Runtime.java:983) JS: com.tns.Runtime.c...

Unexpected results while adding events without and with calendar name

Using the code below will show an alert that the event is created, but it is not visible in the default calendar (tested with iOS 10 and 11 emulator).

If I add

      name: "MyCalendar",

the event is created in the calendar of the iOS emulator, but in the default calendar, not in MyCalendar.

AddtoCalendar() {
    console.log(new Date(new Date().getTime() + 60 * 60 * 1000));
    console.log(new Date(new Date().getTime() + 2 * 60 * 60 * 1000));
    this.createEvent({
      // spans an hour
      title: "Get groceries",
      location: "The shop",
      startDate: new Date(new Date().getTime() + 60 * 60 * 1000),
      endDate: new Date(new Date().getTime() + 2 * 60 * 60 * 1000)
    });
  }

  private createEvent(options): void {
    Calendar.createEvent(options).then(
      createdId => {
        alert({
          title: "Event created with ID",
          message: JSON.stringify(createdId),
          okButtonText: "OK, nice!"
        });
      },
      error => console.log("doCreateEvent error: " + error)
    );
  }

Possible to specify no reminder?

If I set options.reminders = null I then get the default of 60 minutes (at least on iOS). Any way to set the reminder to None?

Android: Cannot delete custom local calendar

Steps to reproduce:

  1. Start app on a device
  2. Create calendar event in a new local custom calendar (by providing calendar: {name: "someName"})
  3. Go to the system calendar app/your preferred calendar app
  4. Try to delete the event (you can't)
  5. Try to delete the calendar (you can't)

The only way I've found to delete the events in the custom/local calendar as well as the custom/local calendar is to go to the settings --> apps --> show system processes --> calendar storage --> delete cache

Haven't tried it on iOS though as I would have to setup everything first in order to deploy it to a device.

[Android] Calendar.findEvents missing id-filter

Hey,

I tried to load a freshly created event (the promise of create event returned "10"), so these options were given to findEvents:
JS: {"startDate":"1970-01-01T00:00:00.000Z","endDate":"2970-01-01T00:00:00.000Z","id":"10"}

According to the documentation:
/**
* Find events matched on ALL params passed in.
*/
this only should find id=10, but it lists every event for the time period. It looks like calendar.android.js is missing the check for the id in Calendar._findEvents line 130 following.

At the moment I cannot test if it works for ios but according to calendar.ios.js there is a check in Calendar.findEvents line 214.

Is this a bug, or is searching by id not supported on android? :)

Thanks for your support!

Torsten

Getting doCreateEvent error: Error: android.database.sqlite.SQLiteException error in android version below 6.

doCreateEvent error: Error: android.database.sqlite.SQLiteException
android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:181)
android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:137)
android.content.ContentProviderProxy.insert(ContentProviderNative.java:420)
android.content.ContentResolver.insert(ContentResolver.java:866)
com.tns.Runtime.callJSMethodNative(Native Method)
com.tns.Runtime.dispatchCallJSMethodNative(Runtime.java:1088)
com.tns.Runtime.callJSMethodImpl(Runtime.java:970)
com.tns.Runtime.callJSMethod(Runtime.java:957)
com.tns.Runtime.callJSMethod(Runtime.java:941)
com.tns.Runtime.callJSMethod(Runtime.java:933)
com.tns.gen.android.content.DialogInterface_OnClickListener.onClick(DialogInterface_OnClickListener.java:12)
com.android.internal.app.AlertController$ButtonHandler.handleMessage(AlertController.java:166)
android.os.Handler.dispatchMessage(Handler.java:99)
android.os.Looper.loop(Looper.java:137)
android.app.ActivityThread.main(ActivityThread.java:5041)
java.lang.reflect.Method.invokeNative(Native Method)
java.lang.reflect.Method.invoke(Method.java:511)
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
dalvik.system.NativeStart.main(Native Method)

All day-events on iOS show up as a 2-day event

I create a new event (set start-time to 0 and end-time to 24 hrs later). I looked at the calendar.ios.js code and given the above, it tags the event as an all-day.

When I view the exported entry in the calendar app - it shows up as a 2-day event.

Interestingly, in the iOS emulator - shows as a 1 day - but on the real device 2 day.

recurrence property not working

@EddyVerbruggen
Every thing works fine but when i add the recurrence property the code breaks.
This is the error I get
`` Types of property 'recurrence' are incompatible.
Type '{ frequency: string; interval: number; endDate: Date; }' is not assignable to type 'Recurrence'.
Types of property 'frequency' are incompatible.
Type 'string' is not assignable to type 'RecurrenceFrequency'.

Handling the permission dialog

When I run the app for the first time using the calendar api, the plug-in prompts for permissions (Android) and I select 'ALLOW' and then nothing happens.

I have to initiate the action again and then it works.

I'm not calling requestPermission() or hasPermissions().

I call plug-in deleteEvents() and then createEvent().

On a related note, I call deleteEvents() to delete all events within a date range and then call createEvent(). When I review the calendar, some created events are no longer there.

I know deleteEvents() returns a promise - do I need to call createEvent() after a successful return from within the promise?

Crashes during require

package.json

{
"dependencies": {
"nativescript-barcodescanner": "1.4.1",
"nativescript-batch": "2.10.3",
"nativescript-calendar": "2.0.0",
"nativescript-loading-indicator": "2.3.2",
"nativescript-phone": "1.2.0",
"nativescript-ui-calendar": "^3.6.0",
"nativescript-ui-core": "^1.0.0",
"nativescript-ui-listview": "3.5.0",
"nativescript-ui-sidedrawer": "3.5.0",
"tns-core-modules": "3.4.0"
},
"devDependencies": {},
"nativescript": {
"id": "com.tentaqle.ucr",
"tns-android": {
"version": "3.4.0"
},
"tns-ios": {
"version": "3.4.0"
}
}
}

home.js
------- This is where it crashes upon require('nativescript-calendar');
'use strict';
var isInit = true,
application = require('application'),
helpers = require('../../utils/widgets/helper'),
http = require("http"),
labelModule = require("ui/label"),
observableArray = require("data/observable-array"),
calendarModule = require("nativescript-ui-calendar"),
moment = require('../../node_modules/moment/moment'),
utilityModule = require("utils/utils"),
calendarPlugin = require('nativescript-calendar'),
frameModule = require("ui/frame"),
dialogs = require("ui/dialogs"),
gestures = require("ui/gestures"),
viewModel = require('./activityFitWellView-view-model');

Bug in deleteEvents()

I'm trying to delete events from a specific calendar.

Looking at the android code - looks like it calls _findEvents() - which seems to return all the events fitting the search criteria - but the calendar name doesn't seem to be one of them...that is it returns all events fitting the criteria from ALL visible calendars.

The the main deleteEvents function - deletes all returned events - i.e. including those from other calendars.

Anyone else confirm this??

List of Event Attendees for Android

Would it be possible to further extend this plugin to utilize the Android CalendarContract.Attendees class to return the list of attendees when using findEvents()? Or is there a reason this hasn't been included yet?

For reference:
https://developer.android.com/reference/android/provider/CalendarContract.Attendees.html

I wanted to ask and put this out there in-case there was a reason this hadn't been included (yet) and/or for someone who is more familiar with this to submit this as a PR.

Add method to modify an existing event

Hey there,

How about implementing the modification of an existing event? Or should we clone the existing event, delete the existing and create a new event with the cloned, modified one?

Cheers,

Feature Suggestion: Check to see if the user has granted permission to access the calendar

Thanks for the module. Very helpful.

I want to only ask for permission to access the calendar (on iOS) if the user clicks on a button so I only include the module when a button is pressed. If the user has not granted access to their calendar before, including the module will prompt them with a message asking for permission to access their calendar. I want to immediately add an item to their calendar as soon as they have done this ... but I can't because there is no call back. It would be very helpful if the module:

  1. Allowed you to query if the user has granted permission.
  2. Had a callback after permission has been granted.

Events not being added in iOS 11.2

It works great in iOS 10 however iOS 11 does not add to calendar.

I've just added the calendar manually and it now creates the events.

Android: Calendar.listCalendars (actually Calendar._findCalendars) results in a crash

Hey there,

So I just updated my apps nativescript-calendar plugin version from 1.0.7 to 1.1.3 (also tried 1.1.1 and 1.1.2) and experience a crash when listing the calendars.

What I do is the following:
My page has a drop down which will/should be filled with available calendars. Therefore I call Calendar.listCalendars() in my ngAfterViewInit to fetch the calendars.
If the permission has not been granted yet, the user will be prompted with the permission dialog (so far so good). If the user then grants the permission the onPermissionGranted callback from Calendar.listCalendars() will be called which will then in turn call Calendar._findCalendars().

In there I receive an exception/stacktrace because Cannot read property 'getContentResolver()' of undefined which is the line application.android.foregroundActivity.getContentResolver() in _findCalendars()

Additional info: If I restart the app after the granting permission crash the listing of the calendars works.

Cannot get list of calendars awailable.

Hi,

I'm trying to use this plugin in my app.
I enabled Calendar API in Google Console, also I have included READ_CALENDAR permission into manifest.

Code:

  import * as Calendar from 'nativescript-calendar';

      Calendar.hasPermission().then((g)=> console.log("Permission granted?", g ? "YES" : "NO"));
      Calendar.requestPermission().then((r)=> console.info(r));
      Calendar.listCalendars().then(
        (c)=> {
          console.dir(c);
          this.calendars= c;
          this.isLoading= false;
        },
        (e)=> {
          console.error(e);
          this.isLoading= false;
        }
      );

And result in console:

JS: 'Error in Calendar.requestPermission: Error: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.app.Activity.requestPermissions(java.lang.String[], int)' on a null object reference'
JS: 'Error in Calendar.listCalendars: Error: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.app.Activity.requestPermissions(java.lang.String[], int)' on a null object reference'
JS: 'Permission granted?' 'NO'
JS: Error: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.app.Activity.requestPermissions(java.lang.String[], int)' on a null object reference

Any ideas what is wrong?

NPE on Android in _requestPermission executed by timeout

Hey,

I just tried to integrate your plugin:

  1. Added plugin
  2. Added require in my component
  3. Added uses-permission to the manifest
  4. Started/Built app for Android

I didn't do anything else than requiring it yet and I am facing an NPE on startup of the component:

android.support.v4.app.ActivityCompat.requestPermissions in Calendar._requestPermission throws an NPE.

"Attempt to invoke virtual method 'void android.app.activity.requestPermissions(params...)' on a null object reference"

There is a function/timer in the calendar.android.js which execute _requestPermission after a second and that's what fails.
(function () {
setTimeout(function() {
if (!Calendar._hasPermission()) {
Calendar._requestPermission();
}
}, 1000);
})();

If I remove this timer everything works fine and I could add a tap action to a button which then requests permission.

Do we even need this timer? Isn't it better to request permission when it will actually be needed/used?

Cheers,

Writing events to a shared calendar that's not read-only.

I'm using the plug-in to create events to a calendar that I create implicitly via the plug-in.

There seems to be two problems - the calendar is created locally only - i.e. not sharable and also the events created are read-only.

For the shareable issue, when I log into the same google account on my computer - the created calendar is not visible. Eventually I'd like to pass an url to someone else so that they can view the same events (read-only is fine).

Re the second issue, read-only is ok - the only problem is that if an event from a read-only calendar, google calendar app doesn't open the event in edit mode - resulting in not being able to view the event description/note.

Permissions issues when using Angular with 4.1.0

Hey Eddy, everything looks good in the emulator, but when moving to a real device i'm getting
"Error creating an Event: TypeError: android.support.v4.content.ContextCompat.checkSelfPermission is not a function"
I checked it out with your demo application and it works correctly on my device. I'm using angular though, and thats the only obvious difference. It even does this when calling check permissions. I have tried with calendar pemissions enabled in my manifest as well.

Here are the relevant portions that fail.

template:
...
<Button (tap)="testCalendar()" text="Test Event">
...

import * as Calendar from 'nativescript-calendar';

@component({
selector: "calcomponent",
moduleId: module.id,
templateUrl: "./cal.component.html"
})
export class CalendarComponent {
testCalendar() {
// Only the title, startDate and endDate are mandatory, so this would suffice:
let options = {
title: 'Get groceries',
startDate: new Date(new Date().getTime() + (60 * 60 * 1000)),
endDate: new Date(new Date().getTime() + (2 * 60 * 60 * 1000)),

        location: 'The shop',
        notes: 'This event has reminders',

        url: <any>'http://my.shoppinglist.com',

        reminders: {
            first: 30,
            second: 10
        },
        recurrence: <any>{
            frequency: "daily", // daily | weekly | monthly | yearly
            interval: 2, // once every 2 days
            endDate: new Date(new Date().getTime() + (10 * 24 * 60 * 60 * 1000)) // 10 days
        },
        calendar: <any>{
            name: "NativeScript Cal",
            color: "#FF0000",
            accountName: "My App Name"
        }
    };

    Calendar.createEvent(options).then(
        function (createdId) {
            console.log("Created Event with ID: " + createdId);
        },
        function (error) {
            console.log("Error creating an Event: " + error);
        }
    );
}

}

How to get recurrence value on findEvents method?

I am trying to create calendar and i want to add all events to calendar. I created an event and choosed recurrence weekly. But in my calendar all weekly recurrence are registered on same day and not weekly. See the screenshots.

Google Calendar get all my events correct. So it is saved correct to calendar! How can i get recurrence value in findEvents method?

screenshot_1507976799
screenshot_1507976804

Android - how to get the permissions prompt

Am not getting the permissions prompt.

I looked at the code and it should do it automatically on module load - but it's not. I call it explicitly and I get the callback with stat = undefined.

var Calendar = require("nativescript-calendar");

Calendar.requestPermission().then( function (stat)
{
console.log( "requestPermission=" + stat );

}, function (e)
{
  console.log( "requestPermission Error=" + e );
} );

In the manifest file, i included both READ_CALENDAR and WRITE_CALENDAR - and rebuilt app.

Failing to create event suddenly

Hi, this was working up until a few hours ago. Now it just fails. Below are the error logs that post to the console, please advise:

Error: java.lang.SecurityException: Permission Denial: reading com.android.providers.calendar.CalendarProvider2 uri content://com.android.calendar/calendars from pid=13891, uid=10281 requires android.permission.READ_CALENDAR, or grantUriPermission()
    android.os.Parcel.readException(Parcel.java:1943)
    android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:183)
    android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:135)
    android.content.ContentProviderProxy.query(ContentProviderNative.java:418)
    android.content.ContentResolver.query(ContentResolver.java:756)
    android.content.ContentResolver.query(ContentResolver.java:705)
    android.content.ContentResolver.query(ContentResolver.java:663)
    com.tns.Runtime.callJSMethodNative(Native Method)
    com.tns.Runtime.dispatchCallJSMethodNative(Runtime.java:1101)
    com.tns.Runtime.callJSMethodImpl(Runtime.java:983)
    com.tns.Runtime.callJSMethod(Runtime.java:970)
    com.tns.Runtime.callJSMethod(Runtime.java:954)
    com.tns.Runtime.callJSMethod(Runtime.java:946)
    com.tns.gen.android.view.GestureDetector_SimpleOnGestureListener_gestures_16_32_TapAndDoubleTapGestureListenerImpl.onSingleTapUp(GestureDetector_SimpleOnGestureListener_gestures_16_32_TapAndDoubleTapGestureListenerImpl.java:17)
    android.view.GestureDetector.onTouchEvent(GestureDetector.java:640)
    android.support.v4.view.GestureDetectorCompat$GestureDetectorCompatImplJellybeanMr2.onTouchEvent(GestureDetectorCompat.java:480)
    android.support.v4.view.GestureDetectorCompat.onTouchEvent(GestureDetectorCompat.java:543)
    com.tns.Runtime.callJSMethodNative(Native Method)
    com.tns.Runtime.dispatchCallJSMethodNative(Runtime.java:1101)
    com.tns.Runtime.callJSMethodImpl(Runtime.java:983)
    com.tns.Runtime.callJSMethod(Runtime.java:970)
    com.tns.Runtime.callJSMethod(Runtime.java:954)
    com.tns.Runtime.callJSMethod(Runtime.java:946)
    com.tns.gen.java.lang.Object_view_30_32_TouchListenerImpl.onTouch(Object_view_30_32_TouchListenerImpl.java:18)
    android.view.View.dispatchTouchEvent(View.java:11755)
    android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3035)
    android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2721)
    android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3035)
    android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2721)
    android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3035)
    android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2721)
    android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3035)
    android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2721)
    android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3035)
    android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2721)
    android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3035)
    android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2721)
    android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3035)
    android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2721)
    android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3035)
    android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2721)
    android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3035)
    android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2721)
    android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3035)
    android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2721)
    android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3035)
    android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2721)
    com.android.internal.policy.DecorView.superDispatchTouchEvent(DecorView.java:464)
    com.android.internal.policy.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1867)
    android.app.Activity.dispatchTouchEvent(Activity.java:3299)
    com.android.internal.policy.DecorView.dispatchTouchEvent(DecorView.java:426)
    android.view.View.dispatchPointerEvent(View.java:11998)
    android.view.ViewRootImpl$ViewPostImeInputStage.processPointerEvent(ViewRootImpl.java:5176)
    android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(ViewRootImpl.java:4990)
    android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:4299)
    android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:4352)
    android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:4318)
    android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:4326)
    android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:4299)
    android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:4352)
    android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:4318)
    android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:4461)
    android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:4326)
    android.view.ViewRootImpl$AsyncInputStage.apply(ViewRootImpl.java:4518)
    android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:4299)
    android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:4352)
    android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:4318)
    android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:4326)
    android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:4299)
    android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:7072)
    android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:7046)
    android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:7007)
    android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent(ViewRootImpl.java:7206)
    android.view.InputEventReceiver.dispatchInputEvent(InputEventReceiver.java:186)
    android.view.InputEventReceiver.nativeConsumeBatchedInputEvents(Native Method)
    android.view.InputEventReceiver.consumeBatchedInputEvents(InputEventReceiver.java:177)
    android.view.ViewRootImpl.doConsumeBatchedInput(ViewRootImpl.java:7154)
    android.view.ViewRootImpl$ConsumeBatchedInputRunnable.run(ViewRootImpl.java:7229)
    android.view.Choreographer$CallbackRecord.run(Choreographer.java:979)
    android.view.Choreographer.doCallbacks(Choreographer.java:791)
    android.view.Choreographer.doFrame(Choreographer.java:720)
    android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:965)
    android.os.Handler.handleCallback(Handler.java:789)
    android.os.Handler.dispatchMessage(Handler.java:98)
    android.os.Looper.loop(Looper.java:164)
    android.app.ActivityThread.main(ActivityThread.java:6710)
    java.lang.reflect.Method.invoke(Native Method)
    com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
    com.android.internal.os.ZygoteInit.main(ZygoteInit.java:770)

It was working perfectly until; I started cleaning my code and removing all console logs so I can do my release build. Do you think I deleted something? Can't find anything wrong in the code.

Problem with building an app with the plugin for Android

There is an issue with building a sample app with nativescript-calendar plugin. This problem could be reproduced with nativescript-calendar-demo only for Android.

Error:

/Users/ntsonev/Desktop/git/ticket1107329/ticket1107329/nativescript-calendar-demo/Calendar/platforms/android/src/main/AndroidManifest.xml:27:9-31 Error:
        Attribute meta-data#android.support.VERSION@value value=(25.3.1) from [com.android.support:design:25.3.1] AndroidManifest.xml:27:9-31
        is also present at [com.android.support:support-v4:26.0.0-alpha1] AndroidManifest.xml:27:9-38 value=(26.0.0-alpha1).
        Suggestion: add 'tools:replace="android:value"' to <meta-data> element at AndroidManifest.xml:25:5-27:34 to override.

See http://g.co/androidstudio/manifest-merger for more information about the manifest merger.

:processF0F1DebugManifest FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':processF0F1DebugManifest'.
> Manifest merger failed : Attribute meta-data#android.support.VERSION@value value=(25.3.1) from [com.android.support:design:25.3.1] AndroidManifest.xml:27:9-31
        is also present at [com.android.support:support-v4:26.0.0-alpha1] AndroidManifest.xml:27:9-38 value=(26.0.0-alpha1).
        Suggestion: add 'tools:replace="android:value"' to <meta-data> element at AndroidManifest.xml:25:5-27:34 to override.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD FAILED

Total time: 1.488 secs
Command /Users/ntsonev/Desktop/git/ticket1107329/ticket1107329/nativescript-calendar-demo/Calendar/platforms/android/gradlew failed with exit code 1

I could not get notes, rrule, begin, end values on ios!

Hi,

I finished the Android version and working with IOS. And there is something that does not work on ios. I do not get up note, rrule (begin and end) values. I have tried to look at the plugin code, but find no solution.

Can anyone help me find a note, rrule its start and end data?

That picture is ios calendar app (showing note) and my app (no note).
simulator screen shot 9 dec 2017 13 17 49

simulator screen shot 9 dec 2017 13 16 26

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.