1

I have a web app where, when user submits a form, iCalendar .ics file is generated server-side and sent back to client with following headers:

'Content-type': 'text/calendar; charset=utf-8',
'Content-Disposition': 'inline; filename=calendar.ics'

While doing this on iOS in Safari browser, the file is processed correctly (event is added to Calendar), but when the app is accessed from home screen, Downloaded Failed This file cannot be downloaded. popup shows up.

Is there any solution to this issue? (Some people have been facing this as well.)

Edit: Just to mention, same thing happens when trying to open base64-encoded .ics file with window.location redirection (as proposed in this answer). I've also created a JS Bin example that can be added to iOS home screen and checked both from there and browser.

Community
  • 1
  • 1
evenfrost
  • 414
  • 5
  • 14

1 Answers1

2

So, I've finally found the way to befriend iOS homescreen app and iCal file generation. I'm using a link of the following format:

<a href="/profile/events/5511a5e88cb9176a13ad9587/ical" target="_self">add to calendar</a>

which leads to server-side route with .ics file generation logic. Then I send back the file with following headers:

'Content-type': 'text/calendar; charset=utf-8',
'Content-Disposition': 'inline; filename=event.ics'

And now it works! Worth mentioning that submitting the form to same route didn't help. And note the target="_self" attribute on anchor, it may be vital for homescreen mode.

Edit: Though the link still opens through browser and not homescreen app. AFAIK, there is currently no workaround for this. I've also update JS Bin example in the question, different options can be tested there.

evenfrost
  • 414
  • 5
  • 14
  • How does it look from the user perspective? Do you see any animation, new tabs opening or prompt for adding event in the calendar? – sha Mar 24 '15 at 18:38
  • Yeah, it opens browser for a moment to get redirected to calendar app. I'll try to prevent default behavior and replace it with `location.href` logic. Will check this a bit later. – evenfrost Mar 24 '15 at 21:22