Windows Phone 8 的 Cordova 日历插件
Cordova calendar plugin for Windows Phone 8
我正在寻找一个 cordova 插件来将事件添加到 Windows Phone 8 日历。 cordova 插件注册表中没有插件。我的解决方法是编写本机插件-
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 来 return 回调。
我做了一个解决方法。维护本地存储标志,数据与事件数据的当前索引。使用您编写的自定义约会插件使用恢复回调来添加其余事件。每次您的应用程序恢复时,您都会增加索引并从下一个索引添加事件数据。
document.addEventListener('resume', this.resumeApp, false)
resumeApp: function () {
if (localStorage.getItem('updatecalendar') == 'false') {
syncUpdatedCalendarWP8();
}
},
在名为 AddCalendarEvents.cs 的插件目录中新建一个 cs 文件并添加以下代码-
using Microsoft.Phone.Tasks;
using Microsoft.Phone.UserData;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using WPCordovaClassLib.Cordova;
using WPCordovaClassLib.Cordova.Commands;
using WPCordovaClassLib.Cordova.JSON;
namespace Cordova.Extension.Commands {
public class AddCalendarEvents: BaseCommand {
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();
}
public void getCalendarEventData(String str) {
ButtonAppointments_Click();
}
private void ButtonAppointments_Click() {
Appointments appts = new Appointments();
//Identify the method that runs after the asynchronous search completes.
appts.SearchCompleted += new EventHandler < AppointmentsSearchEventArgs > (Appointments_SearchCompleted);
DateTime start = DateTime.Now;
DateTime end = start.AddDays(7);
int max = 20;
//Start the asynchronous search.
appts.SearchAsync(start, end, max, "Appointments Test #1");
}
void Appointments_SearchCompleted(object sender, AppointmentsSearchEventArgs e) {
//Do something with the results.
//MessageBox.Show(e.Results.Count().ToString());
try {
e.Results.ToList();
MessageBox.Show("Success");
} catch (System.Exception) {}
}
}
}
参考config.xml-
中的插件
<feature name="AddCalendarEvents">
<param name="wp-package" value="AddCalendarEvents" />
<param name="onload" value="true" />
</feature>
您可以使用
调用它
var inputCalendarString = notes + '|' + title + '|' + location + '|' + appointmentDate.getFullYear() + '|' + (appointmentDate.getMonth() + 1) + '|' + appointmentDate.getDate() + '|' + '1.0' + '|' + ' ';
cordova.exec(null, null, "AddCalendarEvents", "addCalendarEvents", inputCalendarString);
它适用于一个事件,但如果你有事件循环,它将不起作用。要支持多个事件,您可以使用当前事件数据索引维护 Localstorage 标志和数据。使用您编写的自定义约会插件使用恢复回调来添加其余事件。每次您的应用程序恢复时,您都会增加索引并从下一个索引添加事件数据。
document.addEventListener('resume', this.resumeApp, false)
resumeApp: function () {
if (localStorage.getItem('updatecalendar') == 'false') {
syncUpdatedCalendarWP8();
}
}
使用以下插件可以将事件添加到本机 Windows Phone 日历 https://github.com/faGH/fa-plugin-calendar
我正在寻找一个 cordova 插件来将事件添加到 Windows Phone 8 日历。 cordova 插件注册表中没有插件。我的解决方法是编写本机插件-
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 来 return 回调。
我做了一个解决方法。维护本地存储标志,数据与事件数据的当前索引。使用您编写的自定义约会插件使用恢复回调来添加其余事件。每次您的应用程序恢复时,您都会增加索引并从下一个索引添加事件数据。
document.addEventListener('resume', this.resumeApp, false)
resumeApp: function () {
if (localStorage.getItem('updatecalendar') == 'false') {
syncUpdatedCalendarWP8();
}
},
在名为 AddCalendarEvents.cs 的插件目录中新建一个 cs 文件并添加以下代码-
using Microsoft.Phone.Tasks;
using Microsoft.Phone.UserData;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using WPCordovaClassLib.Cordova;
using WPCordovaClassLib.Cordova.Commands;
using WPCordovaClassLib.Cordova.JSON;
namespace Cordova.Extension.Commands {
public class AddCalendarEvents: BaseCommand {
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();
}
public void getCalendarEventData(String str) {
ButtonAppointments_Click();
}
private void ButtonAppointments_Click() {
Appointments appts = new Appointments();
//Identify the method that runs after the asynchronous search completes.
appts.SearchCompleted += new EventHandler < AppointmentsSearchEventArgs > (Appointments_SearchCompleted);
DateTime start = DateTime.Now;
DateTime end = start.AddDays(7);
int max = 20;
//Start the asynchronous search.
appts.SearchAsync(start, end, max, "Appointments Test #1");
}
void Appointments_SearchCompleted(object sender, AppointmentsSearchEventArgs e) {
//Do something with the results.
//MessageBox.Show(e.Results.Count().ToString());
try {
e.Results.ToList();
MessageBox.Show("Success");
} catch (System.Exception) {}
}
}
}
参考config.xml-
中的插件<feature name="AddCalendarEvents">
<param name="wp-package" value="AddCalendarEvents" />
<param name="onload" value="true" />
</feature>
您可以使用
调用它var inputCalendarString = notes + '|' + title + '|' + location + '|' + appointmentDate.getFullYear() + '|' + (appointmentDate.getMonth() + 1) + '|' + appointmentDate.getDate() + '|' + '1.0' + '|' + ' ';
cordova.exec(null, null, "AddCalendarEvents", "addCalendarEvents", inputCalendarString);
它适用于一个事件,但如果你有事件循环,它将不起作用。要支持多个事件,您可以使用当前事件数据索引维护 Localstorage 标志和数据。使用您编写的自定义约会插件使用恢复回调来添加其余事件。每次您的应用程序恢复时,您都会增加索引并从下一个索引添加事件数据。
document.addEventListener('resume', this.resumeApp, false)
resumeApp: function () {
if (localStorage.getItem('updatecalendar') == 'false') {
syncUpdatedCalendarWP8();
}
}
使用以下插件可以将事件添加到本机 Windows Phone 日历 https://github.com/faGH/fa-plugin-calendar