移动 Safari (iOS) 中的 javascript 不会下载日历邀请 [英] javascript in mobile safari (iOS) won't download calendar invite

查看:57
本文介绍了移动 Safari (iOS) 中的 javascript 不会下载日历邀请的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 js 客户端应用程序,我在其中创建了一个日历事件,并希望将其作为 ics 文件下载到客户端.这在桌面浏览器上运行良好,但 iOS 上的移动 Safari(和移动 chrome)拒绝下载它.

I have a js client side application wherein I create a calendar event and want to download it to the client as an ics file. This works fine on desktop browsers, but mobile safari (and mobile chrome) on iOS refuse to download it.

这是我用于该函数的代码:

Here is the code I am using for the function:

let link = document.createElement('a')
// link.setAttribute('target', '_blank')
link.href = ics_string_from_indexedDB
link.download = 'Reminders.ics'
link.click()

当我使用上面的代码并单击我的链接时,移动 Safari 会提示该网站正在尝试向您显示日历邀请.您要允许吗?"带有忽略"和允许"链接.但是点击允许"链接会导致:

When I use the code above and click on my link, mobile safari tells "This website is trying to show you a calendar invite. Do you want to allow this?" with an "Ignore" and "Allow" link. But clicking on the "Allow" link results in:

Safari 无法下载此文件".

"Safari cannot download this file".

我已尝试按照其他地方的建议添加目标(并在上面进行了注释),但这也不起作用,如果存在,单击我的链接根本没有任何作用.

I have tried adding a target as suggested elsewhere (and commented out above), but that doesn't work either, and clicking on my link does nothing at all if present.

我也尝试过创建一个 blob,但 safari 拒绝以完全相同的方式下载它.

I have also tried creating a blob, but safari refuses to download that in the exact same way.

我也尝试过 base64 编码,但 safari 再次拒绝(并给出 404)

I have also tried base64 encoding, but again safari refuses (and gives a 404)

有谁知道允许 iOS Safari(客户端)将此文件下载到日历的方法吗?

Does anyone know of a way to allow iOS safari (client side) to download this file to the calendar?

旁注:如果我改为从服务器发送 ical 流并设置各种标头,我可以让它工作,但我想在客户端完成这一切并且不明白为什么我需要一个服务器,所有存在正确的 ics 信息.

side note: I can get this working if I send the ical stream from a server instead and set various headers, but I want to do this all on the client side and don't see why I should need a server, all of the correct ics info is present.

推荐答案

好吧,我自己解决了这个问题,这是我学到的:

Well, I solved this myself, here is what I learned:

Mobile Safari 对于它认为是有效 .ics 文件的内容非常挑剔,它根本无法识别它不喜欢的文件.即使它是有效的,并且即使桌面上的 iCal 和其他应用程序(以及桌面上的 Safari!)将识别并导入这些 ics 文件也很好.

Mobile Safari is VERY PICKY about what it considers to be a valid .ics file, and it simply won't recognize a file that it doesn't like. Even though it is valid, and even though iCal and other apps on the desktop (and Safari on the desktop!) will recognize and import these ics files just fine.

我使用了我之前在服务器上使用的相同 php 生成器,因为它似乎以 Mobile Safari 喜欢的格式制作文件.我没有时间详尽地测试它需要哪些字段,哪些不需要,但是如果我不得不猜测查看源代码,它可能与时区相关,或者可能与 UID 的格式有关.如果我在这个项目之后有时间,我会尝试在这方面获得更多的特异性.

I used the same php generator I was using before on my server because it seems to make files in a format that Mobile Safari likes. I don't have the time to exhaustively test which fields it requires and doesn't, but if I had to guess looking at the source, it is maybe timezone related or perhaps the formatting of the UID. If I get the time after this project I will try to get some more specificity on this.

一旦我的格式一切正常,从我的本地 indexedDB 下载 blob 现在就可以正常工作了:

Once my format was all ok, blob downloading from my local indexedDB now works just fine:

let blob = new Blob([ics_string_from_indexedDB], { type: 'text/calendar' })
let link = document.createElement('a')
link.href = window.URL.createObjectURL(blob)
link.download = 'Reminders.ics'
link.click()

这篇关于移动 Safari (iOS) 中的 javascript 不会下载日历邀请的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆