Programmatically add event in iPhone/Android Calendar with PhoneGap/jQuery Mobile?

22,034

Solution 1

Per the comments below, it is now possible to create an iCal file for iOS and a vcs file for Android. It will require browser/device sniffing, or give the user the choice, but it should at least be possible.

Solution 2

I realize it's old question but there is plugin for this now. It has its cons, but works. At the moment of writing it supports the following functionality:

  • iOS supports: create (silently), update (silently) and delete (silently) event
  • Android >= 4: create (interactively and silently), update (not supported), delete (silently) event
  • Android < 4: create (interactively), update (not supported), delete (not supported) event

Here follows code example:

  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 newTitle = "My new 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); 
  };

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

  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);

Solution 3

Currently the PhoneGap development roadmap does not include calendar support. However, there are many requests for it. See this post called "Calendar plugin following W3C calendar API" which points to the PhoneGap-Calendar-Plugin project which includes some initial calendar support for Android.

Solution 4

Adding an event to the iOS calendar is very simple with the latest API. However, you need to create your own plugin in order to do it.

since this is platform specific, come time will pass before there is an official PhoneGap plugin.

Solution 5

I found plugins for Android and iOS but they do not have the same JavaScript API so you have to write different code for both systems or add another layer. Also they are not up to date and will need fixes to run with Cordova 2.2.0. To make things worse documentation is kind of short:

Android

Dcheng's Android Plugin is able to create, remove and search calender events but is totally outdated and will not work as it is. With Android 4.0 there is a Calendar Provider that makes things easier but still I did not find a good plugin. jbajor can only add events and twistandshout only search events.

iOS

Felixactv8's iOS Plugin is able to create, remove and search calender events. Notice that in iOS there is no event id, so searching your events will be fun. The author explains how to add the two needed frameworks in xcode:

the iphone calendar uses the 2 frameworks, EventKit.framework and EventKitUI.framework.

if you click on the xcode icon, you should see the project icon and the target icon. click on the target icon, then click build phases. Click the dropdown for "Link Binary with libraries. Click the plus sign at the bottom of the window, then search for both frameworks. Add both of those frameworks, rebuild the project and run it.

Share:
22,034

Related videos on Youtube

Michael Schmidt
Author by

Michael Schmidt

Updated on July 03, 2020

Comments

  • Michael Schmidt
    Michael Schmidt almost 4 years

    How can I create a calendar event from a JavaScript / jQuery Mobile / PhoneGap app in iOS/Android?

    Are there any, e.g., PhoneGap plugins? Didn't see any in the official repository.

    • For iOS, the Event Kit framework (iOS 4.0+) seems to be able to add an event.
  • Kaiesh
    Kaiesh almost 12 years
    Unfortunately, that doesn't actually work... I recently opened a question on how to do exactly that as iCal is not supported by Android
  • superjos
    superjos over 11 years
    As that SO discussion shows now, you can create an iCal file for iPhone and a vCal file for Android.
  • PiTheNumber
    PiTheNumber about 11 years
    Also it's not on the Cordova roadmap wiki.apache.org/cordova/RoadmapProjects
  • Adam Tuttle
    Adam Tuttle almost 11 years
    @superjos thanks for pointing that out. I'm going to edit it in. Now I just wish this answer had more votes so it would stand out.