Search code examples
javascripticalendar

Add alert to iCal data/calendar Object


I created a URL that opens the calendar App on iOS devices, with some predefined info. This is my code:

window.location = encodeURI(
  'data:text/calendar;charset=utf8,' +
    [
      'BEGIN:VCALENDAR',
      'VERSION:2.0',
      'BEGIN:VEVENT',
      'URL:' + document.URL,
      'DTSTART:' + formatTime(startDate),
      'DTEND:' + formatTime(endDate),
      'SUMMARY:' + eventName,
      'DESCRIPTION:' + description,
      'LOCATION:' + location,
      'END:VEVENT',
      'END:VCALENDAR',
      'TRIGGER:-P15M'
    ].join('\n')
);

Ignoring all the variables, it works fine. The only thing not working is the alert. By default, when it opens it says alert: "None". I want a 15 minute alert by default.

I tried using "TRIGGER:-P15M" but it didn't work. Is it possible to do so?


Solution

  • You need to add VALARM with time offset

    BEGIN:VALARM
    TRIGGER:-PT30M
    REPEAT:1
    ACTION:AUDIO
    END:VALARM
    

    within VEVENT object. You may also specify URL for alert file, but I'm not sure if it works in iOS

    For advanced reading check out RFC https://www.rfc-editor.org/rfc/rfc5545#section-3.6.6 for VALARM