【问题标题】:Cordova calendar plugin for Windows Phone 8适用于 Windows Phone 8 的 Cordova 日历插件
【发布时间】:2015-08-17 21:22:46
【问题描述】:

我正在寻找一个用于向 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);

它适用于一个事件,但如果我有事件循环,它就不起作用。它不会进入科尔多瓦成功回调。如果有人写了这样的插件,那将是非常有帮助的。

【问题讨论】:

    标签: javascript cordova windows-phone-8 phonegap-plugins


    【解决方案1】:

    你在哪里声明了成功回调? 根据我的说法,你的 js 中的代码应该是 -

    cordova.exec(successCallback, failureCallback, 'AddCalendarEvents', 'addCalendarEvents', inputCalendarString);

     function successCallback(success){
         console.log('Success');
     }
    
     function failureCallback(error){
         console.log('Failure');
     }
    

    此外,您需要在 .cs 文件中使用 DispatcherCommandResult 来返回回调。

    【讨论】:

    • developer.ibm.com/mobilefirstplatform/documentation/… 看看这个。您将知道如何使用 DispatchCommandResult 方法将结果返回给 JavaScript,无论是成功还是失败。
    • DispacherCommandResult 在成功打开设备日历界面时触发。我想在事件创建成功时触发它。
    【解决方案2】:

    我做了一个解决方法。维护本地存储标志,数据与事件数据的当前索引。使用您编写的自定义约会插件使用恢复回调添加其余事件。每次您的应用恢复时,您都会增加索引并从下一个索引添加事件数据。

    document.addEventListener('resume', this.resumeApp, false)
     resumeApp: function () {
            if (localStorage.getItem('updatecalendar') == 'false') {
                syncUpdatedCalendarWP8();
            }
        },
    

    【讨论】:

      【解决方案3】:

      使用以下插件可以将事件添加到本机 Windows Phone 日历https://github.com/faGH/fa-plugin-calendar

      【讨论】:

      • 确实 :) 一定会在本周末之前添加。现在,它是您发布的内容的工作包。
      【解决方案4】:

      在名为 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();
            }
      }
      

      Reference

      【讨论】:

      • 嗨,我似乎无法正常工作。你能帮帮我吗?像你在这篇文章中所说的那样完成。好像每次我用 phonegap 重建时,wp8 目录中的 config.xml 都会清除我为此插件添加的功能节点。另外,我注意到所有其他插件都有一个专用的目录。我是否必须在插件目录中为此插件创建一个目录,或者只是将其放在根目录中?最后,我将插件放在哪个插件目录中? wp8特定的一个还是phonegap项目根目录下的plugins目录?
      • 你能给我一个你的插件的github链接吗?我将非常感激 :)
      • 你能从这里试试吗-nickalchemist.wordpress.com/2015/04/08/… 需要一些时间才能上传到 Github。
      • 嗨,我已经用你提供的代码创建了一个插件,但由于未知原因它不起作用:(你能看看,也许可以解决我搞砸的问题并提出拉取请求?github.com/faGH/WPCalendarPlugin
      • 想检查一下——您在项目中是否使用了其他 PhoneGap 插件?
      猜你喜欢
      • 2014-12-08
      • 2014-10-19
      • 1970-01-01
      • 2012-11-30
      • 1970-01-01
      • 2013-10-29
      • 2013-02-14
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多