我正在寻找一个 cordova 插件来将事件添加到 Windows Phone 8 日历。 cordova 插件注册表中没有插件。我的解决方法是编写 native 插件-
public void addCalendarEvents(String str)
{
string[] calendarValues = str.Split('|');
SaveAppointmentTask saveAppointmentTask = new SaveAppointmentTask();
int appointmentYear = Int32.Parse(calendarValues[3]);
int appointmentMonth = Int32.Parse(calendarValues[4]);
int appointmentDate = Int32.Parse(calendarValues[5]);
float appointmentTime = float.Parse(calendarValues[6]);
DateTime scheduleApptDateStart = (new DateTime(appointmentYear, appointmentMonth, appointmentDate, 7, 0, 0)).AddHours(appointmentTime);
DateTime scheduleApptDateEnd = (new DateTime(appointmentYear, appointmentMonth, appointmentDate, 7, 30, 0)).AddHours(appointmentTime);
saveAppointmentTask.StartTime = scheduleApptDateStart;
saveAppointmentTask.EndTime = scheduleApptDateEnd;
saveAppointmentTask.Subject = calendarValues[1];
saveAppointmentTask.Location = calendarValues[2];
saveAppointmentTask.Details = "";
saveAppointmentTask.IsAllDayEvent = false;
saveAppointmentTask.Reminder = Reminder.FifteenMinutes;
saveAppointmentTask.AppointmentStatus = Microsoft.Phone.UserData.AppointmentStatus.Busy;
saveAppointmentTask.Show();
}
并使用
调用它 var inputCalendarString = notes + '|' + title + '|' + location + '|' + appointmentDate.getFullYear() + '|' + (appointmentDate.getMonth() + 1) + '|' + appointmentDate.getDate() + '|' + '1.0' + '|' + ' ';
cordova.exec(null, null, "AddCalendarEvents", "addCalendarEvents", inputCalendarString);
它适用于一个事件,但如果我有事件循环,它就不起作用。它不会进入 cordova 成功回调。如果有人写了这样的插件,那将是非常有帮助的。
最佳答案
你在哪里声明成功回调? 根据我的说法,你的 js 中的代码应该是 -
cordova.exec(successCallback, failureCallback, 'AddCalendarEvents', 'addCalendarEvents', inputCalendarString);
function successCallback(success){
console.log('Success');
}
function failureCallback(error){
console.log('Failure');
}
此外,您需要在 .cs 文件中使用 DispatcherCommandResult 来返回回调。
关于javascript - 适用于 Windows Phone 8 的 Cordova 日历插件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28166510/