'This file cannot be downloaded' 尝试在主屏幕网络应用程序中访问 ics 文件时

'This file cannot be downloaded' when trying to access ics file in homescreen web app

我有一个网络应用程序,当用户提交表单时,会生成 iCalendar .ics 文件 server-side 并通过以下 headers:

发送回客户端
'Content-type': 'text/calendar; charset=utf-8',
'Content-Disposition': 'inline; filename=calendar.ics'

在 Safari 浏览器中 iOS 上执行此操作时,文件已正确处理(事件已添加到日历),但是当从主屏幕访问该应用程序时,会显示 Downloaded Failed This file cannot be downloaded. 弹出窗口。

这个问题有什么解决办法吗? ()

编辑:顺便提一下,当尝试使用 window.location 重定向打开 base64 编码的 .ics 文件时会发生同样的事情(如 ). I've also created a JS Bin example 中所建议的,可以添加到 iOS主屏幕并从那里和浏览器检查。

所以,我终于找到了 iOS 主屏幕应用程序和 iCal 文件生成的好方法。我正在使用以下格式的 link:

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

导致 server-side 路由与 .ics 文件生成逻辑。然后我将文件发回 headers:

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

现在可以了!值得一提的是,将表单提交到同一路线并没有帮助。并注意锚点上的 target="_self" 属性,这对于主屏幕模式可能至关重要。

编辑: 虽然 link 仍然通过浏览器而不是主屏幕应用程序打开。 AFAIK,目前没有解决方法。我还在问题中更新了 JS Bin 示例,可以在那里测试不同的选项。