如何在本机日历中添加事件 - IONIC

问题描述 投票:0回答:1

简要说明:我使用下面的代码在android中插入一个事件,我怎么能在我的代码中包含firstReminderMinutessecondReminderMinutes

请注意,我刚刚在构造函数中硬编码了一个事件。

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,请指导?

cordova ionic-framework ionic2 ionic3 cordova-plugins
1个回答
0
投票

要在创建事件时包含firstReminderMinutessecondReminderMinutes,您可以使用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查看离子原生日历的所有信息

© www.soinside.com 2019 - 2024. All rights reserved.