找到你要的答案

Q:Using calendar plugin in Phonegap for Android and IOS

Q:使用日历插件在Android和iOS PhoneGap

I am using phonegap build (build.phonegap.com) to create .apk and .ipa files for android and IOS respectively. I have used calendar plugin (https://github.com/EddyVerbruggen/Calendar-PhoneGap-Plugin/blob/cc57eeec417f7a41d8ffcb07a0986192df4fb712/README.md)

I have followed its documentation and added following line in config.xml

<gap:plugin name="nl.x-services.plugins.calendar" />

And used following code to create event

var startDate = new Date(2014,4,29,18,30,0,0,0); // beware: month 0 = january, 11 = december
  var endDate = new Date(2014,4,29,19,30,0,0,0);
  var title = "LeadSquared Event";
  var location = "myleads.html";
  var notes = "LeadSquared Event test.";
  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);

But the event is not getting added in the calendar. Where I am doing mistake?

我使用PhoneGap构建(Build。PhoneGap。com)创建。apk。分别为Android和iOS IPA文件。我用日历插件(https://github.com/eddyverbruggen/calendar-phonegap-plugin/blob/cc57eeec417f7a41d8ffcb07a0986192df4fb712/readme.md)

我跟着它的文件和添加以下行在config.xml

<gap:plugin name="nl.x-services.plugins.calendar" />

使用下列代码创建事件

var startDate = new Date(2014,4,29,18,30,0,0,0); // beware: month 0 = january, 11 = december
  var endDate = new Date(2014,4,29,19,30,0,0,0);
  var title = "LeadSquared Event";
  var location = "myleads.html";
  var notes = "LeadSquared Event test.";
  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);

但事件不会在日历中添加。我在哪里犯错误?

answer1: 回答1:

The problem was that I wasn't waiting for deviceready to fire. So I modified the code and it worked fine.

 function calendar_events(){
 var startDate = new Date(2014,4,31,18,30,0,0,0); // beware: month 0 = january, 11 = december
  var endDate = new Date(2014,4,31,19,30,0,0,0);
  var title = "Skype meeting With Lead";
 //var location = "myleads.html";
  var notes = "Need to do a skype meeting with the lead.";
  var success = function(message) { alert("Success: " + JSON.stringify(message)); };
  var error = function(message) { alert("Error: " + message); };
  // window.plugins.calendar.listEventsInRange(startDate,endDate,success,error);

//  window.plugins.calendar.createCalendar(calendarName,success,error);
  window.plugins.calendar.createEvent(title,location,notes,startDate,endDate,success,error);
 }
 document.addEventListener("deviceready", calendar_events, false);

问题是,我不是在等待deviceready火。所以我修改了代码,它运行良好。

 function calendar_events(){
 var startDate = new Date(2014,4,31,18,30,0,0,0); // beware: month 0 = january, 11 = december
  var endDate = new Date(2014,4,31,19,30,0,0,0);
  var title = "Skype meeting With Lead";
 //var location = "myleads.html";
  var notes = "Need to do a skype meeting with the lead.";
  var success = function(message) { alert("Success: " + JSON.stringify(message)); };
  var error = function(message) { alert("Error: " + message); };
  // window.plugins.calendar.listEventsInRange(startDate,endDate,success,error);

//  window.plugins.calendar.createCalendar(calendarName,success,error);
  window.plugins.calendar.createEvent(title,location,notes,startDate,endDate,success,error);
 }
 document.addEventListener("deviceready", calendar_events, false);
android  cordova  phonegap-plugins  phonegap-build