adamgibbons / ics

iCalendar (ics) file generator for node.js
ISC License
715 stars 152 forks source link

Not able to generate an ics file that could add an event on iCalendar #185

Open amartya-dev opened 3 years ago

amartya-dev commented 3 years ago

I have tested it multiple times, but as soon as I generate an ics file and add an event with it in my iPhone, it almost always fails.

My code:

ics.createEvent(
        {
          title: this.webinarTitle,
          start: [
            date.getFullYear(),
            date.getMonth(),
            date.getDay(),
            date.getHours(),
            date.getMinutes(),
          ],
          duration: { hours: this.webinarDuration },
          organizer: {
            name:
              this.webinarHost.first_name + ' ' + this.webinarHost.last_name,
            email: this.webinarHost.email,
          },
        },
        (error, value) => {
          if (error) {
            console.log(error)
          }
          var filename = `${this.webinarTitle}-invite.ics`
          console.log(value)
          var blob = new Blob([value], {
            type: 'text/calendar;charset=utf8',
            encoding: 'UTF-8',
          })
          console.log(blob.type)
          if (window.navigator.msSaveOrOpenBlob) {
            window.navigator.msSaveBlob(blob, filename)
          } else {
            var elem = window.document.createElement('a')
            elem.href = window.URL.createObjectURL(blob)
            elem.download = filename
            document.body.appendChild(elem)
            elem.click()
            document.body.removeChild(elem)
          }
        }
      )
ramseth001 commented 2 years ago

I am also facing this issue

Jp3rd commented 2 years ago

I have tested it multiple times, but as soon as I generate an ics file and add an event with it in my iPhone, it almost always fails.

My code:

ics.createEvent(
        {
          title: this.webinarTitle,
          start: [
            date.getFullYear(),
            date.getMonth(),
            date.getDay(),
            date.getHours(),
            date.getMinutes(),
          ],
          duration: { hours: this.webinarDuration },
          organizer: {
            name:
              this.webinarHost.first_name + ' ' + this.webinarHost.last_name,
            email: this.webinarHost.email,
          },
        },
        (error, value) => {
          if (error) {
            console.log(error)
          }
          var filename = `${this.webinarTitle}-invite.ics`
          console.log(value)
          var blob = new Blob([value], {
            type: 'text/calendar;charset=utf8',
            encoding: 'UTF-8',
          })
          console.log(blob.type)
          if (window.navigator.msSaveOrOpenBlob) {
            window.navigator.msSaveBlob(blob, filename)
          } else {
            var elem = window.document.createElement('a')
            elem.href = window.URL.createObjectURL(blob)
            elem.download = filename
            document.body.appendChild(elem)
            elem.click()
            document.body.removeChild(elem)
          }
        }
      )

Here is what I did that worked:

const { value } = createEvent(event);
const data = new Blob([value], { type: 'text/calendar' });

do not add UTF-8 as encoding.

coderdix24 commented 1 year ago

I'm placing it in an Uint8Array typed array with a format of 'ics' and its not working. having to do this to upload to cloudinary cdn

ajainzimyo commented 1 year ago

Anyone to help here. Facing the same issue.