我正在使用phonegap build(build.phonegap.com)分别为android和IOS创建.apk和.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);
但事件未在日历中添加。我在哪里做错了?
答案 0 :(得分:2)
问题在于我没有等待设备准备好开火。所以我修改了代码并且工作正常。
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);