如何在本机日历中添加事件 - IONIC
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了如何在本机日历中添加事件 - IONIC相关的知识,希望对你有一定的参考价值。
简要说明:我使用下面的代码在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
,请指导?
答案
要在创建事件时包含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
);
你可以在qazxsw poi查看离子原生日历的所有信息
以上是关于如何在本机日历中添加事件 - IONIC的主要内容,如果未能解决你的问题,请参考以下文章