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

前端 未结 5 1180
感情败类
感情败类 2021-02-01 04:24

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

相关标签:
5条回答
  • 2021-02-01 04:56

    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.

    0 讨论(0)
  • 2021-02-01 05:00

    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);
    
    0 讨论(0)
  • 2021-02-01 05:11

    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.

    0 讨论(0)
  • 2021-02-01 05:15

    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.

    0 讨论(0)
  • 2021-02-01 05:16

    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.

    0 讨论(0)
提交回复
热议问题