简要说明:我使用下面的代码在android中插入一个事件,如何在代码中包含firstReminderMinutes
和secondReminderMinutes
?
请注意,我刚刚在构造函数中对一个事件进行了硬编码。
home.ts
代码:
import { Component } from '@angular/core';
import { NavController,AlertController } from 'ionic-angular';
import { Calendar } from '@ionic-native/calendar';
@Component({
selector: 'page-home',
templateUrl: 'home.html'
})
export class HomePage {
event;
constructor(public navCtrl: NavController,private calendar: Calendar,public alertCtrl: AlertController) {
this.event = { title: "Event created from Quick Task", location: "Jalandhar", message: "Visit", startDate: "17 Mar 2018 13:30", endDate: "16 Mar 2018 14:30" };
// this.calendar.createCalendar('MyCalendar').then(
// (msg) => { console.log(msg); },
// (err) => { console.log(err); }
// );
this.calendar.createEvent( this.event.title, this.event.location, this.event.message, new Date(this.event.startDate), new Date(this.event.endDate)).then(
(msg) => {
let alert = this.alertCtrl.create({
title: 'Success!',
subTitle: 'Event saved successfully',
buttons: ['OK']
});
alert.present();
this.navCtrl.pop();
},
(err) => {
let alert = this.alertCtrl.create({
title: 'Failed!',
subTitle: err,
buttons: ['OK']
});
alert.present();
}
);
}
}
我应该使用this.calendar.createCalendar
代替this.calendar.createEvent
吗,请指导?
答案 0 :(得分:0)
要在创建活动时加入firstReminderMinutes
和secondReminderMinutes
,您可以使用方法createEventWithOptions
,如下例所示
// create an event silently (on Android < 4 an interactive dialog is
shown which doesn't use this options) with options:
var calOptions = window.plugins.calendar.getCalendarOptions(); // grab the defaults
calOptions.firstReminderMinutes = 120; // default is 60, pass in null for no reminder (alarm)
calOptions.secondReminderMinutes = 5;
// Added these options in version 4.2.4:
calOptions.recurrence = "monthly"; // supported are: daily, weekly, monthly, yearly
calOptions.recurrenceEndDate = new Date(2016,10,1,0,0,0,0,0); // leave null to add events into infinity and beyond
calOptions.calendarName = "MyCreatedCalendar"; // iOS only
calOptions.calendarId = 1; // Android only, use id obtained from listCalendars() call which is described below. This will be ignored on iOS in favor of calendarName and vice versa. Default: 1.
// This is new since 4.2.7:
calOptions.recurrenceInterval = 2; // once every 2 months in this case, default: 1
// And the URL can be passed since 4.3.2 (will be appended to the notes on Android as there doesn't seem to be a sep field)
calOptions.url = "https://www.google.com";
// on iOS the success handler receives the event ID (since 4.3.6)
window.plugins.calendar.createEventWithOptions(
title,eventLocation,notes,startDate,
endDate,calOptions,success,error
);
您可以在https://github.com/EddyVerbruggen/Calendar-PhoneGap-Plugin
查看离子日历的所有信息