Giter Site home page Giter Site logo

eddyverbruggen / calendar-phonegap-plugin Goto Github PK

View Code? Open in Web Editor NEW
774.0 41.0 403.0 606 KB

:date: Cordova plugin to Create, Change, Delete and Find Events in the native Calendar

Objective-C 32.35% JavaScript 17.12% Java 50.53%
cordova phone calendar agenda event

calendar-phonegap-plugin's Introduction

PhoneGap Calendar plugin

NPM version Downloads TotalDownloads Twitter Follow

paypal Every now and then kind folks ask me how they can give me all their money. Of course I'm happy to receive any amount but I'm just as happy if you simply 'star' this project.

  1. Description
  2. Installation 2. Automatically 2. Manually 2. PhoneGap Build
  3. Usage
  4. Promises
  5. Credits
  6. License

1. Description

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

iOS specifics

  • Supported methods: find, create, modify, delete, ..
  • All methods work without showing the native calendar. Your app never loses control.
  • Tested on iOS 6+.
  • On iOS 10+ you need to provide a reason to the user for Calendar access. This plugin adds an empty NSCalendarsUsageDescription key to the /platforms/ios/*-Info.plist file which you can override with your custom string. To do so, pass the following variable when installing the plugin:
cordova plugin add cordova-plugin-calendar --variable CALENDAR_USAGE_DESCRIPTION="This app uses your calendar"

Android specifics

  • Supported methods on Android 4: find, create (silent and interactive), delete, ..
  • Supported methods on Android 2 and 3: create interactive only: the user is presented a prefilled Calendar event. Pressing the hardware back button will give control back to your app.

Windows 10 Mobile

  • Supported methods: createEvent, createEventWithOptions, createEventInteractively, createEventInteractivelyWithOptions only interactively

2. Installation

Automatically

Latest release on npm:

$ cordova plugin add cordova-plugin-calendar

Bleeding edge, from github:

$ cordova plugin add https://github.com/EddyVerbruggen/Calendar-PhoneGap-Plugin.git

Manually

iOS

1. Add the following xml to your config.xml:

<!-- for iOS -->
<feature name="Calendar">
	<param name="ios-package" value="Calendar" />
</feature>

2. Grab a copy of Calendar.js, add it to your project and reference it in index.html:

<script type="text/javascript" src="js/Calendar.js"></script>

3. Download the source files for iOS and copy them to your project.

Copy Calendar.h and Calendar.m to platforms/ios/<ProjectName>/Plugins

4. Click your project in XCode, Build Phases, Link Binary With Libraries, search for and add EventKit.framework and EventKitUI.framework.

Android

1. Add the following xml to your config.xml:

<!-- for Android -->
<feature name="Calendar">
  <param name="android-package" value="nl.xservices.plugins.Calendar" />
</feature>

2. Grab a copy of Calendar.js, add it to your project and reference it in index.html:

<script type="text/javascript" src="js/Calendar.js"></script>

3. Download the source files for Android and copy them to your project.

Android: Copy Calendar.java to platforms/android/src/nl/xservices/plugins (create the folders/packages). Then create a package called accessor and copy other 3 java Classes into it.

4. Add these permissions to your AndroidManifest.xml:

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

Note that if you don't want your app to ask for these permissions, you can leave them out, but you'll only be able to use one function of this plugin: createEventInteractively.

PhoneGap Build

Add the following xml to your config.xml to always use the latest npm version of this plugin:

<plugin name="cordova-plugin-calendar" />

Also, make sure you're building with Gradle by adding this to your config.xml file:

<preference name="android-build-tool" value="gradle" />

3. Usage

The table gives an overview of basic operation compatibility:

Operation Comment iOS Android Windows
createCalendar yes yes
deleteCalendar yes yes
createEvent silent yes yes * yes **
createEventWithOptions silent yes yes * yes **
createEventInteractively interactive yes yes yes **
createEventInteractivelyWithOptions interactive yes yes yes **
findEvent yes yes
findEventWithOptions yes yes
listEventsInRange yes yes
listCalendars yes yes
findAllEventsInNamedCalendars yes
modifyEvent yes
modifyEventWithOptions yes
deleteEvent yes yes
deleteEventFromNamedCalendar yes
deleteEventById yes yes
openCalendar yes yes
  • * on Android < 4 dialog is shown
  • ** only interactively on windows mobile

Basic operations, you'll want to copy-paste this for testing purposes:

  // prep some variables
  var startDate = new Date(2015,2,15,18,30,0,0,0); // beware: month 0 = january, 11 = december
  var endDate = new Date(2015,2,15,19,30,0,0,0);
  var title = "My nice event";
  var eventLocation = "Home";
  var notes = "Some notes about this event.";
  var success = function(message) { alert("Success: " + JSON.stringify(message)); };
  var error = function(message) { alert("Error: " + message); };

  // create a calendar (iOS only for now)
  window.plugins.calendar.createCalendar(calendarName,success,error);
  // if you want to create a calendar with a specific color, pass in a JS object like this:
  var createCalOptions = window.plugins.calendar.getCreateCalendarOptions();
  createCalOptions.calendarName = "My Cal Name";
  createCalOptions.calendarColor = "#FF0000"; // an optional hex color (with the # char), default is null, so the OS picks a color
  window.plugins.calendar.createCalendar(createCalOptions,success,error);

  // delete a calendar
  window.plugins.calendar.deleteCalendar(calendarName,success,error);

  // create an event silently (on Android < 4 an interactive dialog is shown)
  window.plugins.calendar.createEvent(title,eventLocation,notes,startDate,endDate,success,error);

  // create an event silently (on Android < 4 an interactive dialog is shown which doesn't use this options) with options:
  var calOptions = window.plugins.calendar.getCalendarOptions(); // grab the defaults
  calOptions.firstReminderMinutes = 120; // default is 60, pass in null for no reminder (alarm)
  calOptions.secondReminderMinutes = 5;

  // Added these options in version 4.2.4:
  calOptions.recurrence = "monthly"; // supported are: daily, weekly, monthly, yearly
  calOptions.recurrenceEndDate = new Date(2016,10,1,0,0,0,0,0); // leave null to add events into infinity and beyond
  calOptions.calendarName = "MyCreatedCalendar"; // iOS only
  calOptions.calendarId = 1; // Android only, use id obtained from listCalendars() call which is described below. This will be ignored on iOS in favor of calendarName and vice versa. Default: 1.

  // This is new since 4.2.7:
  calOptions.recurrenceInterval = 2; // once every 2 months in this case, default: 1

  // And the URL can be passed since 4.3.2 (will be appended to the notes on Android as there doesn't seem to be a sep field)
  calOptions.url = "https://www.google.com";

  // on iOS the success handler receives the event ID (since 4.3.6)
  window.plugins.calendar.createEventWithOptions(title,eventLocation,notes,startDate,endDate,calOptions,success,error);

  // create an event interactively
  window.plugins.calendar.createEventInteractively(title,eventLocation,notes,startDate,endDate,success,error);

  // create an event interactively with the calOptions object as shown above
  window.plugins.calendar.createEventInteractivelyWithOptions(title,eventLocation,notes,startDate,endDate,calOptions,success,error);

  // create an event in a named calendar (iOS only, deprecated, use createEventWithOptions instead)
  window.plugins.calendar.createEventInNamedCalendar(title,eventLocation,notes,startDate,endDate,calendarName,success,error);

  // find events (on iOS this includes a list of attendees (if any))
  window.plugins.calendar.findEvent(title,eventLocation,notes,startDate,endDate,success,error);

  // if you need to find events in a specific calendar, use this one. All options are currently ignored when finding events, except for the calendarName.
  var calOptions = window.plugins.calendar.getCalendarOptions();
  calOptions.calendarName = "MyCreatedCalendar"; // iOS only
  calOptions.id = "D9B1D85E-1182-458D-B110-4425F17819F1"; // if not found, we try matching against title, etc
  window.plugins.calendar.findEventWithOptions(title,eventLocation,notes,startDate,endDate,calOptions,success,error);

  // list all events in a date range (only supported on Android for now)
  window.plugins.calendar.listEventsInRange(startDate,endDate,success,error);

  // list all calendar names - returns this JS Object to the success callback: [{"id":"1", "name":"first"}, ..]
  window.plugins.calendar.listCalendars(success,error);

  // find all _future_ events in the first calendar with the specified name (iOS only for now, this includes a list of attendees (if any))
  window.plugins.calendar.findAllEventsInNamedCalendar(calendarName,success,error);

  // change an event (iOS only for now)
  var newTitle = "New title!";
  window.plugins.calendar.modifyEvent(title,eventLocation,notes,startDate,endDate,newTitle,eventLocation,notes,startDate,endDate,success,error);

  // or to add a reminder, make it recurring, change the calendar, or the url, use this one:
  var filterOptions = window.plugins.calendar.getCalendarOptions(); // or {} or null for the defaults
  filterOptions.calendarName = "Bla"; // iOS only
  filterOptions.id = "D9B1D85E-1182-458D-B110-4425F17819F1"; // iOS only, get it from createEventWithOptions (if not found, we try matching against title, etc)
  var newOptions = window.plugins.calendar.getCalendarOptions();
  newOptions.calendaName = "New Bla"; // make sure this calendar exists before moving the event to it
  // not passing in reminders will wipe them from the event. To wipe the default first reminder (60), set it to null.
  newOptions.firstReminderMinutes = 120;
  window.plugins.calendar.modifyEventWithOptions(title,eventLocation,notes,startDate,endDate,newTitle,eventLocation,notes,startDate,endDate,filterOptions,newOptions,success,error);

  // delete an event (you can pass nulls for irrelevant parameters). The dates are mandatory and represent a date range to delete events in.
  // note that on iOS there is a bug where the timespan must not be larger than 4 years, see issue 102 for details.. call this method multiple times if need be
  // since 4.3.0 you can match events starting with a prefix title, so if your event title is 'My app - cool event' then 'My app -' will match.
  window.plugins.calendar.deleteEvent(newTitle,eventLocation,notes,startDate,endDate,success,error);

  // delete an event, as above, but for a specific calendar (iOS only)
  window.plugins.calendar.deleteEventFromNamedCalendar(newTitle,eventLocation,notes,startDate,endDate,calendarName,success,error);

  // delete an event by id. If the event has recurring instances, all will be deleted unless `fromDate` is specified, which will delete from that date onward. (iOS and android only)
  window.plugins.calendar.deleteEventById(id,fromDate,success,error);

  // open the calendar app (added in 4.2.8):
  // - open it at 'today'
  window.plugins.calendar.openCalendar();
  // - open at a specific date, here today + 3 days
  var d = new Date(new Date().getTime() + 3*24*60*60*1000);
  window.plugins.calendar.openCalendar(d, success, error); // callbacks are optional

Creating an all day event:

  // set the startdate to midnight and set the enddate to midnight the next day
  var startDate = new Date(2014,2,15,0,0,0,0,0);
  var endDate = new Date(2014,2,16,0,0,0,0,0);

Creating an event for 3 full days

  // set the startdate to midnight and set the enddate to midnight 3 days later
  var startDate = new Date(2014,2,24,0,0,0,0,0);
  var endDate = new Date(2014,2,27,0,0,0,0,0);

Example Response IOS getCalendarOptions

{
calendarId: null,
calendarName: "calendar",
firstReminderMinutes: 60,
recurrence: null,
recurrenceEndDate: null,
recurrenceInterval: 1,
secondReminderMinutes: null,
url: null
}

Exmaple Response IOS Calendars

{
id: "258B0D99-394C-4189-9250-9488F75B399D",
name: "standard calendar",
type: "Local"
}

Exmaple Response IOS Event

{
calendar: "Kalender",
endDate: "2016-06-10 23:59:59",
id: "0F9990EB-05A7-40DB-B082-424A85B59F90",
lastModifiedDate: "2016-06-13 09:14:02",
location: "",
message: "my description",
startDate: "2016-06-10 00:00:00",
title: "myEvent"
}

Android 6 (M) Permissions

On Android 6 you need to request permission to use the Calendar at runtime when targeting API level 23+. Even if the uses-permission tags for the Calendar are present in AndroidManifest.xml.

Since plugin version 4.5.0 we transparently handle this for you in a just-in-time manner. So if you call createEvent we will pop up the permission dialog. After the user granted access to his calendar the event will be created.

You can also manually manage and check permissions if that's your thing. Note that the hasPermission functions will return true when:

  • You're running this on iOS, or
  • You're targeting an API level lower than 23, or
  • You're using Android < 6, or
  • You've already granted permission.
  // again, this is no longer needed with plugin version 4.5.0 and up
  function hasReadWritePermission() {
    window.plugins.calendar.hasReadWritePermission(
      function(result) {
        // if this is 'false' you probably want to call 'requestReadWritePermission' now
        alert(result);
      }
    )
  }

  function requestReadWritePermission() {
    // no callbacks required as this opens a popup which returns async
    window.plugins.calendar.requestReadWritePermission();
  }

There are similar methods for Read and Write access only (hasReadPermission, etc), although it looks like that if you request read permission you can write as well, so you might as well stick with the example above.

Note that backward compatibility was added by checking for read or write permission in the relevant plugins functions. If permission is needed the plugin will now show the permission request popup. The user will then need to allow access and invoke the same method again after doing so.

4. Promises

If you like to use promises instead of callbacks, or struggle to create a lot of events asynchronously with this plugin then I encourage you to take a look at this awesome wrapper for this plugin. Kudos to John Rodney for this piece of art!

5. Credits

This plugin was enhanced for Plugman / PhoneGap Build by Eddy Verbruggen. I fixed some issues in the native code (mainly for iOS) and changed the JS-Native functions a little in order to make a universal JS API for both platforms.

6. License

The MIT License (MIT)

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

calendar-phonegap-plugin's People

Contributors

1b0t avatar abcdev avatar alexandre-machado avatar alexbuijs avatar angjelkom avatar botweb avatar brabeji avatar chemerisuk avatar dtretter avatar eddyverbruggen avatar freundschaft avatar grzesiekmq avatar karabanovbs avatar kingsfleet avatar malloc32 avatar mserranog avatar nkoded avatar p-schuler avatar pablosomarriba avatar peterpeterparker avatar philhardy avatar samedii avatar scurker avatar signalwerk avatar syndbg avatar thedewi avatar tiagomsmagalhaes avatar ujnamss avatar vip-git avatar vkusiak 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  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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 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

calendar-phonegap-plugin's Issues

Error when trying to install

tcowin@macbookpro[/Development/SETACMeetingApp]$ phonegap local plugin add https://github.com/EddyVerbruggen/Calendar-PhoneGap-Plugin.git
[phonegap] adding the plugin: https://github.com/EddyVerbruggen/Calendar-PhoneGap-Plugin.git

/usr/local/lib/node_modules/phonegap/node_modules/cordova/node_modules/plugman/src/util/config-changes.js:364
throw new Error('grafting xml at s
^
Error: grafting xml at selector "widget" from "/Development/SETACMeetingApp/platforms/android/res/xml/config.xml" during config install went bad :(
at /usr/local/lib/node_modules/phonegap/node_modules/cordova/node_modules/plugman/src/util/config-changes.js:364:51
at Array.forEach (native)
at /usr/local/lib/node_modules/phonegap/node_modules/cordova/node_modules/plugman/src/util/config-changes.js:331:63
at Array.forEach (native)
at /usr/local/lib/node_modules/phonegap/node_modules/cordova/node_modules/plugman/src/util/config-changes.js:315:45
at Array.forEach (native)
at Object.module.exports.add_plugin_changes (/usr/local/lib/node_modules/phonegap/node_modules/cordova/node_modules/plugman/src/util/config-changes.js:310:35)
at /usr/local/lib/node_modules/phonegap/node_modules/cordova/node_modules/plugman/src/util/config-changes.js:410:28
at Array.forEach (native)
at Object.module.exports.process (/usr/local/lib/node_modules/phonegap/node_modules/cordova/node_modules/plugman/src/util/config-changes.js:409:49)

Android success/cancel having no distinction

As identified in this commit 8e41ba5 I guess reverting the changes here ecb922f would solve the problem for now?

I can see why this success/error callback makes sense with iOS where the plugin acts on the users calendar directly but it's not so useful when calling an Intent I guess?

[Android] "success" is fired, even if the event is canceled

I clicked on a button to add an event into my calendar. The event shows up and gives me the possibility to edit the event and to save or cancel it. A click on cancel wouldn't add the event to my calendar, but fires the success event back to my app. Any suggestions?

Error build after add plugin in cordova

Hi,
I have a project with android and iOS, with cordova 3.3. When add the plugin, the plugin add without problem but when build I get this error:

Error: An error occurred while building the ios project.2014-01-23 16:36:30.574 xcodebuild[36038:4403]  DeveloperPortal: Using pre-existing current store at URL (file:///Users/manuelcm/Library/Developer/Xcode/DeveloperPortal%205.0.2.db).
2014-01-23 16:36:31.342 xcodebuild[36047:5903]  DeveloperPortal: Using pre-existing current store at URL (file:///Users/manuelcm/Library/Developer/Xcode/DeveloperPortal%205.0.2.db).
2014-01-23 16:36:32.134 xcodebuild[36057:4507]  DeveloperPortal: Using pre-existing current store at URL (file:///Users/manuelcm/Library/Developer/Xcode/DeveloperPortal%205.0.2.db).
** BUILD FAILED **


The following build commands failed:
    Ld build/device/Talent.upc.app/Talent.upc normal armv7
(1 failure)
** BUILD FAILED **


The following build commands failed:
    Ld build/emulator/Talent.upc.app/Talent.upc normal i386
(1 failure)

    at ChildProcess. (/usr/local/lib/node_modules/cordova/src/compile.js:65:22)
    at ChildProcess.EventEmitter.emit (events.js:98:17)
    at maybeClose (child_process.js:735:16)
    at Socket. (child_process.js:948:11)
    at Socket.EventEmitter.emit (events.js:95:17)
    at Pipe.close (net.js:466:12)

If do the build only for android get this error:

Error: An error occurred while building the android project.Error executing "ant debug -f "/Users/manuelcm/Documents/test.ischool.fundacioupc.com/platforms/android/build.xml"": 
BUILD FAILED
/Users/manuelcm/Documents/sdk_android/tools/ant/build.xml:653: The following error occurred while executing this line:
/Users/manuelcm/Documents/sdk_android/tools/ant/build.xml:698: null returned: 1

Total time: 4 seconds


    at ChildProcess. (/usr/local/lib/node_modules/cordova/src/compile.js:65:22)
    at ChildProcess.EventEmitter.emit (events.js:98:17)
    at maybeClose (child_process.js:735:16)
    at Socket. (child_process.js:948:11)
    at Socket.EventEmitter.emit (events.js:95:17)
    at Pipe.close (net.js:466:12)

When remove the plugin all works fine.

I need also a social sharing plugin, and i try https://github.com/EddyVerbruggen/SocialSharing-PhoneGap-Plugin
and when build for iOS get the same error (android build fine)
Thanks

App breaks from thread warning

In the console log I am receiving this warning from the plugin.

THREAD WARNING: ['Calendar'] took '6732.648926' ms. Plugin should use a background thread.

createEvent doesn't work on android

hi,
createEvent() doesn't work on android (4.4), it returns "invalid action", although createEventInteractively() works. Last commit where it works is bf9f0b5. (I was using example code from readme)

Problem reading events

this is my code:

showEvents : function(callback){
var calendarName = 'Eventos';
window.plugins.calendar.findAllEventsInNamedCalendar(calendarName,app.success,app.error);
callback();
},success : function(message) {

    app.mensaje = JSON.stringify(message);

alert("Success:" + JSON.stringify(message));
},
error : function(message) {
    alert("Error: " + message);
}

My problem is when I call my showEvents function sometimes it retrieves me empty response, but is not giving me an error, It enters in the success function, even if i create my events in Calendar App or via this plugin it retrieves me my response empty, but when this happens I discovered that if i create a new event via Calendar App it only brings me that event, not the other ones, only those who were created after it failed.

I hope you can help me.

Thanks in advance, happy new year :)

iOS createEvent

Hello.

We use createEvent function for creating new event in calendar. On Android it works, but on iOS called error callback with message about 'localizeddescription no calendar set'.
We don't use named calendar, how to fix it?

iPad iOS 6.1.3, iPhone 4, iPhone 5.

Create calendar with color

When creating a calendar with a name, it would be ideal to also be able to set the color of the calendar.

iOS: Calendar Find Event

The calendar find event method breaks the application with error:

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason:
'Unable to parse the format string "title == 'Event Title' AND location == 'Address' AND notes == 'Event Notes
'"'

Note: I replaced the event details with dummy text, if you want to see the original content please let me know.

When I checked the Calendar.m file I found the following semanticError Method definition for 'findEKEventsWithTitle:location:message:startDate:endDate:calendar' not found

I can confirm that findEvent method is working fine on Android Devices and the above issue is only affecting iOS

iOS problem with build.phonegap.com

Hi,
When I use build service, window.plugins.calendar is undefined on ios (I build android locally and it works fine).
I inspected ipa file and I can't see calendar plugin defined in www/cordova_plugins.js file. Structure is also weird - all plugins are in www/plugins directory (followed by fully qualified plugin name) but Calendar.js is in www/js/plugins directory.

I use phonegap 3.1.0 and latest calendar plugin (3.2 I suppose).

Also it would be great if you find some time to add find method for android version (now I can add the same event infinite number of times).

Works flawlessly on Android but not on iOS

Using Telerik AppBuilder, the following works for Android but not iOS
app.testCal = function(e) {
var startDate = new Date("September 24, 2013 13:00:00");
var endDate = new Date("September 24, 2013 14:30:00");
var title = "My nice event";
var location = "Home";
var notes = "Some notes about this event.";
var success = function(message) { navigator.notification.alert("Success: " + JSON.stringify(message)); };
var error = function(message) { navigator.notification.alert("Error: " + message); };

    window.plugins.calendar.createEvent(title,location,notes,startDate,endDate,success,error);
};

I have a link on index.html as such
Test Cal

For Android, the event is created, you can edit it, then save it, control is returned to the app. For iOS nothing happens, no error, no nothing....

Any ideas?
Thank you
Robert

createEventInteractively

Hi Eddy,

Really cool plugin 👍

I have some questions though.

Q1. Why iOS doesn't support "adding events interactively" ?

Q2. On Andorid, when adding events interactively, i can able to see the calendar overlay before adding the event. But, if i click "cancel" in the overlay, "success callback" is getting called instead of "failure callback". Why is it so ? (I can internally call "findEvent" and then call the correct callback but is it possible to do from the plugin itself ?)

Thanks,
Vigneswaran M

Add events to calander

Hi I have an app that when a user clicks on a marker on a google map it opens an info window which displays details about the event from mysql database. Is it possible to click a button to add an event to the phones calander using this plugin when the register button is clicked. See screenshot. Thanks
media-20140214

feedback some solution for you

such kind of this

new Date("January 25, 2014 14:30:00");

but in the Practice conditions,the month "name" (January) should not be Stationary,but the month name is hard to get,so I made a javascript and php solution way

in javascript

function getNowTime(action)
{
var now = new Date();
 if(action == 'year')
 {
 var vars = now.getFullYear();
 }
 if(action == 'month')
 {
 var vars = new Array('January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September','October', 'November', 'December');
 var vars = vars[now.getMonth()];
 //var vars = (now.getMonth()+1< 10)?("0" + (now.getMonth() + 1)):(now.getMonth() + 1);
 }
 if(action == 'day')
 {
 var vars = (now.getDate() < 10)?("0" + (now.getDate())):(now.getDate());
 }
 if(action == 'hours')
 {
 var vars = now.getHours();
 }
 if(action == 'minutes')
 {
 var vars = now.getMinutes();
 }
 if(action == 'seconds')
 {
 var vars = now.getSeconds();
 }
return vars;
}

so use the method getNowTime('month') will get the month name,getNowTime('year') will get the year,etc....

in php

function Month($NumMonth)
{
 switch($NumMonth)
 {
 case "01": return "January"; break; 
 case "02": return "February"; break; 
 case "03": return "March"; break; 
 case "04": return "April"; break; 
 case "05": return "May"; break; 
 case "06": return "June"; break; 
 case "07": return "July"; break; 
 case "08": return "August"; break; 
 case "09": return "September"; break; 
 case "10": return "October"; break; 
 case "11": return "November"; break; 
 case "12": return "December"; break; 
 }
}

so use the method will get the month name

maybe you can Consider to change the month "name" to "Digital"
January => 01
February => 02
if could,it will be more Direct

"createEventWithOptions" seem no affect in Android and ios

I am using PGB 3.3 and your latest plugin 4.2.1
this is all your sample code

var startDate = new Date(2014,2,15,18,30,0,0,0);
var endDate = new Date(2014,2,15,19,30,0,0,0);
var title = "My nice event";
var location = "Home";
var notes = "Some notes about this event.";
var success = function(message) { alert("Success: " + JSON.stringify(message)); };
var error = function(message) { alert("Error: " + message); };

var calOptions = window.plugins.calendar.getCalendarOptions(); // grab the defaults
options.firstReminderMinutes = 120; // default is 60, pass in null for no reminder (alarm)
window.plugins.calendar.createEventWithOptions(title,location,notes,startDate,endDate,options,success,error);

but when I execute it
there is no any success callback or error callback (no response)

Android Calendar Date Format

Is the date format in the example the only acceptable date format? Can you lease add this to the doco?

Thanks again for taking the time to write this plugin.

createEventInteractively in iOS

Hi Eddy,

I am not a Objective C developer. So, bare with my question. I found a link for "Modifying Calendar Event" in IOS.

https://developer.apple.com/library/ios/documentation/DataManagement/Conceptual/EventKitProgGuide/UsingEventViewControllers.html#//apple_ref/doc/uid/TP40009765-CH2-SW4

In the above link, kindly look into "Modifying Event Data". Does the example shows how to open the "Calendar Edit Overlay" ? If so, is it possible to add event interactively in iOS ?

Regards,

Vigneswaran M

Newbie Advice

Hi Eddy.
Newbie here.
I think I got it installed, but sorry to say, the steps I don't think is the clearest.
Under implementation you mention: Basic operations, you'll want to copy-paste this for testing purposes:
But you don't mention where.
Do you have anywhere a working example? Sorry for any dumb questions, kinda new to phonegap and plugins. I just want to have a page that has a few input fields that populates the diary entry.
Hope you can help.
Thanks,
Johann

All days events are one day late on Android

On my HTC One running Kit Kat, my all day events are displaying one day late on the calendar. I noticed in the code for AbstractCalendarAccessor.createEvent(), if it is an all day event, one day is added to the start date. What is the reason for this?

The Android and iOS issue

Android 4.0.3,HTC Sensation XL
iOS7.0.4,iPad mini,the original version is 6.1.2

This is my full code

function makeCalendar() 
{
var title = "小包的主題"; //主題
var startDate = new Date("December 24, 2013 13:00:00"); //開始日期
var endDate = new Date("December 25, 2013 14:30:00"); //結束日期
var location = "小包的地點"; //地點
var notes = "小包的說明"; //說明
var success = function(message) { navigator.notification.alert("成功:" + JSON.stringify(message), null, endMessage_title, endMessage_botton.split(",")[0]); };
var error = function(message) { navigator.notification.alert("失敗:" + message, null, endMessage_title, endMessage_botton.split(",")[0]); };

window.plugins.calendar.createEvent(title,location,notes,startDate,endDate,success,error);
window.plugins.calendar.findEvent(title,location,notes,startDate,endDate,success,error);
var newTitle = "新的主題";
window.plugins.calendar.modifyEvent(title,location,notes,startDate,endDate,newTitle,location,notes,startDate,endDate,success,error);
window.plugins.calendar.deleteEvent(newTitle,location,notes,startDate,endDate,success,error);
}

in Android,this function is work,but the "endDate" is not correct
http://www.littlebau.com/ca01.png

in iOS,this function is not work
http://www.littlebau.com/ca02.png

New version 4.0 have issues

I am in Android 4.0.3,but I think that ios have the same problem too

When I use PGB 3.3 with your 3.2 version,your .js file is a Independent individuals,it under such kind of directory,so I use this way...

<script type="text/javascript" src="js/Calendar.js"></script>

everything is all work with your sample code

but when I use PGB 3.3 with your 4.0 version,your .js file is become Automatically loadind by cordova_plugins.js

so...the line in the html should be delete
script type="text/javascript" src="js/Calendar.js" /script>

cordova_plugins.js

{
"file": "plugins/nl.x-services.plugins.calendar/www/Calendar.js",
"id": "nl.x-services.plugins.calendar.Calendar",
"clobbers": ["Calendar"]
}

everything is all broken with your same sample code...

Android - Delete event

Manage to get working - add calendar event and find calendar event.
However I have not been able to get delete calendar event to work.
window.plugins.calendar.deleteEvent(title,location,notes,startDate,endDate,success,error);

When I call the API, I always get "success:false" return. I have passed in the same params when creating the calender event and find calender event. Have tried it on emulator (4.3 API 18) and on mobile HTC 1 (v 4.4) and Samsung Mini (4.3). All fails. If u need any more info let me know.

Class not found in android

Hi and thanks for this plugin

I'm trying to use this plugin in my app (using phonegap build 2.9) and under ios 7 works perfect, but when I try to use it under android (4.2.2 in my tests) i got the error: "class not found".

I'm using this line (acording the documentation) window.plugins.calendar.createEvent(title,location,notes,startDate,endDate,success,error);

Any idea about this issue?

PhoneGap 3.4: Class not found

Using this plugin with PhoneGap 3.4 on Android with any org.apache.cordova.* plugin installed results in either an initial "Error initializing Cordova: Class not found" error or a "Class not found" error in response to all methods of the window.plugins.calendar object.

After reverting to PhoneGap 3.3, e.g. npm install -g [email protected], there is no initial error and methods respond as expected.

Builds are created using phonegap local build android or phonegap local run android.

App close in ios when the date is recovering from localstorage

I don't know if this is issue or I'm making something bad... any one has the same problem??

If I use this code, the example, and it works perfect in android and ios app.

var startDate = new Date("September 24, 2013 13:00:00");
var endDate = new Date("September 24, 2013 14:30:00");
var title = "My nice event";
var location = "Home";
var notes = "Some notes about this event.";
var success = function(message) { alert("Success: " + JSON.stringify(message)); };
var error = function(message) { alert("Error: " + message); };

// create (the only function also supported on Android for now)
window.plugins.calendar.createEvent(title,location,notes,startDate,endDate,success,error);

When I try to get the startDate and endDate from a saved data using localstorage the app broke under ios (closes) but works perfect under android when calendar pluging is called. For example this code:

window.localStorage.setItem("value_start", "September 24, 2013 13:00:00");
window.localStorage.setItem("value_end", "September 24, 2013 13:00:00");

var value_start=window.localStorage.getItem("value_start);
var value_end=window.localStorage.getItem("value_end);

var startDate = new Date(value_start);
var endDate = new Date(value_end);
var title = "My nice event";
var location = "Home";
var notes = "Some notes about this event.";
var success = function(message) { alert("Success: " + JSON.stringify(message)); };
var error = function(message) { alert("Error: " + message); };

// create (the only function also supported on Android for now)
window.plugins.calendar.createEvent(title,location,notes,startDate,endDate,success,error);

Thanks :)

Creating Recurring Events

Hi,

I don't see the option to create recurring events. I am guessing the only way to do this using the current version of the plugin would be to create multiple events for the duration and frequency of the recurrence. Is that right?

Any plans to support recurrences for iOS?

Thanks,
Sri

iOS 6.1 crashes

createEventWithOptions crashes in iOS 6.1 with the following exception:

-[NSNull doubleValue]: unrecognized selector sent to instance 0x3b130090
2014-04-17 09:18:39.600 HelloCordova[196:907] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSNull doubleValue]: unrecognized selector sent to instance 0x3b130090'
*** First throw call stack:
(0x32e602a3 0x3aabc97f 0x32e63e07 0x32e62531 0x32db9f68 0xb12c3 0xb419d 0xa9ef1 0xa978f 0x3376e277 0x32e355df 0x32e35291 0x32e33f01 0x32da6ebd 0x32da6d49 0x369232eb 0x34cbc301 0xaf7db 0x3aef3b20)
libc++abi.dylib: terminate called throwing an exception

Add Event to android calendar Silently

Dear Sir,

Thanks for the great plugin.
Is there any way to add the event silently without showing the add Event Window of the native Calendar in android.

Alarms add on

we are developing an app using this great plugin (thanks for developing it), I want to increase their functionality adding alarms to the functions, what should I read or check to help me developing this add-on???

iOS findEvent callbacks not firing

findEvent's callbacks aren't firing on iOS, neither success or error. I have tested it on Android and I'm finding no problems.

I'm using v4.2.2 of the plugin, and my iPhone is an iPhone 4 with iOS v7.1.

I have definitely allowed the app to access my calendar, too :)

Here's the code which isn't getting into the callback:

var createdSuccess = function (message) {
    console.log('Calendar event created:', message);
    if (_.isFunction(options.success)) {
        options.success(message);
    }
};

var createdError = function(message) {
    console.log('Calendar event creation error:', message);
    if (_.isFunction(options.error)) {
        options.error(message);
    }
};

var lookupError = function(message) {
    console.log('Calendar event lookup error:', message);
    if (_.isFunction(options.error)) {
        options.error(message);
    }
};

window.plugins.calendar.findEvent(title, '', null, startDate, endDate, function (eventsFound) {
    if (eventsFound && eventsFound.length > 0) {
        console.log('Not adding any new events');
        return;
    }
    window.plugins.calendar.createEvent(title, '', notes, startDate, endDate, createdSuccess, createdError);
}, lookupError);

Keep in mind that title, startDate and endDate have all been defined and are definitely not undefined, as is _, and I have already checked for the existence of window.plugins.calendar.

I am getting no exceptions from anything.

Am I doing something wrong, or is this a bug?

Any help would be appreciated, thanks :)

iOS Calendar.m method definition error or javascript problem

Hi,

I've been trying for the last week to add your plugin to my app. Unfortunately I have had no luck with even so much as a response to the native calendar on iOS. Could the method definition error be the root of the problem?
This is the error in xcode:
screen shot 2014-03-15 at 2 05 26 pm

Here is also my javascript code if this could also be the problem:

 function Calendar_Add() {

   var startDate = new Date(2014,2,15,18,30,0,0,0); // beware: month 0 = january, 11 = december
   var endDate = new Date(2014,2,15,19,30,0,0,0);
   var calendarName = ""
   var title = "";
   var location = place;
   var notes = "";
   var success = function(message) { alert("Success: " + JSON.stringify(message)); };
  var error = function(message) { alert("Error: " + message); };

  window.plugins.calendar.createCalendar(calendarName,success,error);
  window.plugins.calendar.findEvent(title,location,notes,success,error);
   window.plugins.calednar.createEventInNamedCalendar(title,location,notes,startDate,endDate,calendarName,success,error);


}
  function IE_navigate(index) {

Bindex = index;

$.mobile.changePage('#eventPage', 'slidefade');

$.each(data, function(i,item){
    if (i == Bindex) {
          //Clear if page was previously populated


          //Populate page
          $('#page-title').html(item.title + "<br />");
          $('#page-region').html(item.Region + "<br />");
          $('#page-content').html(item.fullInfo + "<br />");
  //var year = moment(item.Date,"YYYY,MM,DD,hh,mm,s,ms,a");

             startDate = new Date(item.Date);
             endDate = new Date(item.Date);
             title = item.title;
             place = item.Region;
             calendarName = item.title;

          $(this).ready(function(e) {
              $('#page-content').on('click','a', function(e){
                e.preventDefault();
                currentPage = $(this).attr('href');
               window.open(currentPage, '_system', 'location=yes')
           });
          });
         // return false;

          return false
    }
});
 };

Thank you,
David

IOS 6 deprecation

'calendarWithEventStore' method and 'calendars' property have both been deprecated in IO6, will there be a fix for this soon. Apple is no longer accepting apps targeted for IOS6

Request access to calendar on IOS 6+

Looks like, plugin doesnt ask for calendar permission on IOS 6/7 devices.
After calling standard window.plugins.calendar.createEvent(...) fail callback is called with message "no calendar has been set". Looks like on new IOS version you have to call for permission first, before you can actually work with calendar.

Assign unique ID to event

The current parameters (title, location, notes, startDate, endDate) are subject to change in some scenarios, making it hard to interact with the calendar. Assigning an ID to the event which will not change regardless of the other parameters changing will make looking up and deleting events easier.

ios calendar feature

how would you add feature for repeat (every day, every week...) and alarm (e.g. on time, 5 min before...) in ios...

it would be nice if the plugin can do that...

thanks

Not working

Hello,

first of all great plugin. My Problem is that I can't get it working :(
I did it the way you descriped in your readme but i will always get the error "uncaught TypeError: Cannot read property "calendar" of undefinied. I am trying to get it run for Android 4.3 with Cordova 2.8.
Could you please help me.

Best Regards,
Manuel

iOS crashes if you block app from accessing calendar

If you try to use the plugin on iOS when the user has blocked the PhoneGap/Cordova app from accessing the calendar (Settings > Privacy > Calendar), the app crashes instantly:

2014-04-04 16:58:31.496 App Name[1227:60b] defaultCalendarForNewEvents failed: Error Domain=EKCADErrorDomain Code=1013 "The operation couldn’t be completed. (EKCADErrorDomain error 1013.)"
2014-04-04 16:58:31.499 App Name[1227:60b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[__NSPlaceholderArray initWithObjects:count:]: attempt to insert nil object from objects[0]'
*** First throw call stack:
(0x301fcfd3 0x3a945ccf 0x30136acb 0x30139119 0xa711f 0xa9219 0x9e159 0x9da7b 0x9d629 0x9d80f 0x9d721 0x30be5c73 0x301c825b 0x301c772b 0x301c5f1f 0x30130f4f 0x30130d33 0x35052663 0x32a7c16d 0xa3de3 0x3ae52ab7)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)

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.