javascript - 适用于 Windows Phone 8 的 Cordova 日历插件

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

我正在寻找一个 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/

相关文章:

c# - Windows Phone 后退按钮

javascript - 使用正则表达式测试 IP 地址

javascript - 使用网络移动框架?

cordova - 如何使用 navigator.app.exitApp() 在 iOS 平台的cordova 中退出应用程序?

iphone - PhoneGap/iPhone/zxing

windows-phone-8 - 将 Windows Phone 8 模拟器(在 VirtualBox 上)连接到 Visual Studio(在主机上)

c# - 发出异步休息请求

javascript - 正则表达式在双引号之间查找换行符并替换为空格

javascript - rxjs 最终在 promise 解析之前执行

javascript - 嵌套对象上的 JSON.stringify 忽略嵌套对象