一、插件简介
Calendar插件允许用户在日历中创建活动、查询活动、删除活动。可以在X5APP内实现对活动的管理,提高用户在你APP小船中的驻留时间。当然,用户也可离开X5APP,在手机的“日历”里查看在活动。
插件ID:cordova-plugin-calendar。
二、插件使用
0、参数准备
require("cordova!cordova-plugin-calendar"); Model.prototype.setParameters = function(event) { this.title = "X5开发者大会";// 标题 this.location = "北京国际会议中心";// 地点 this.notes = "九点前签到,有大牛到场。干货分享会。";// 内容 this.start = new Date(); this.end = new Date(); this.start.setMinutes(0); this.end.setMinutes(0); this.start.setSeconds(0); this.end.setSeconds(0); this.start.setHours(this.start.getHours() + 2); this.end.setHours(this.end.getHours() + 3); this.calendarName = "我的X5日历";// 活动 this.success = function(message) { justep.Util.hint("Success: " + JSON.stringify(message)); }; this.error = function(message) { justep.Util.hint("Error: " + message); }; };
1、打开日历
Model.prototype.openCalendarClick = function(event) { var cal = window.plugins.calendar; cal.openCalendar(); };
2、创建一个活动(交互方式)
Model.prototype.createEventInteractivelyClick = function(event) { var cal = window.plugins.calendar; cal.createEventInteractively(this.title, this.location, this.notes, this.start, this.end, this.success, this.error); };
3、创建一个带通知活动(参数方式)
Model.prototype.createEventWithOptionsClick = function(event) { var calOptions = window.plugins.calendar.getCalendarOptions(); calOptions.url = "http://www.wex5.com"; calOptions.firstReminderMinutes = 120; calOptions.secondReminderMinutes = 60; calOptions.recurrence = "monthly"; calOptions.recurrenceEndDate = new Date(2025, 10, 1, 0, 0, 0, 0, 0); calOptions.recurrenceInterval = 2; var cal = window.plugins.calendar; cal.createEventWithOptions(this.title, this.location, this.notes, this.start, this.end, calOptions, this.success, this.error); };
4、创建一个无通知活动(参数方式)
Model.prototype.createEventClick = function(event) { var cal = window.plugins.calendar; cal.createEvent(this.title, this.location, this.notes, this.start, this.end, this.success, this.error); };
5、查询活动
Model.prototype.listEventsInRange = function(event) { var fromDate = new Date(); var toDate = new Date(); toDate.setFullYear(2050); var cal = window.plugins.calendar; cal.listEventsInRange(fromDate, toDate, this.success, this.error); };
6、删除活动
Model.prototype.deleteEventClick = function(event) { var cal = window.plugins.calendar; cal.deleteEvent(this.title, this.location, this.notes, this.start, this.end, this.success, this.error); };
7、Android下按日期范围查询
Model.prototype.findEventClick = function(event) { var cal = window.plugins.calendar; cal.findEvent(this.title, this.location, this.notes, this.start, this.end, this.success, this.error); };
8、IOS下操作个人日历
//创建个人日历 Model.prototype.createCalendar = function(event) { var cal = window.plugins.calendar; cal.createCalendar(this.calendarName, this.success, this.error); }; //在个人日历创建活动 Model.prototype.createEventInNamedCalendar = function(event) { var cal = window.plugins.calendar; cal.createEventInNamedCalendar(this.title, this.location, this.notes, this.start, this.end, this.calendarName, this.success, this.error); }; //在个人日历中查找活动 Model.prototype.findAllEventsInNamedCalendar = function(event) { var cal = window.plugins.calendar; cal.findAllEventsInNamedCalendar(this.calendarName, this.success, this.error); }; //删除个人日历 Model.prototype.deleteCalendar = function(event) { var cal = window.plugins.calendar; cal.deleteCalendar(this.calendarName, this.success, this.error); };
三、说明
在IOS中,如果创建个人日历失败,需要先在IOS设置中,把iCloud日历开启,作用是同步到云。然后进行创建。
评一波