admin管理员组文章数量:1415491
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()
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 cannot download this file".
I have tried adding a target as suggested elsewhere (and mented out above), but that doesn't work either, and clicking on my link does nothing at all if present.
I have also tried creating a blob, but safari refuses to download that in the exact same way.
I have also tried base64 encoding, but again safari refuses (and gives a 404)
Does anyone know of a way to allow iOS safari (client side) to download this file to the calendar?
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.
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()
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 cannot download this file".
I have tried adding a target as suggested elsewhere (and mented out above), but that doesn't work either, and clicking on my link does nothing at all if present.
I have also tried creating a blob, but safari refuses to download that in the exact same way.
I have also tried base64 encoding, but again safari refuses (and gives a 404)
Does anyone know of a way to allow iOS safari (client side) to download this file to the calendar?
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.
Share Improve this question edited Jul 8, 2018 at 13:23 Stephen asked Jul 8, 2018 at 12:12 StephenStephen 8,2487 gold badges47 silver badges59 bronze badges2 Answers
Reset to default 5Well, I solved this myself, here is what I learned:
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.
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.
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()
I had similar problem, iPhone doesn't want to recognize .ics file. Problem was in charset=utf-8
let blob = new Blob([ics_string_from_indexedDB], { type: 'text/calendar;charset=utf-8' })
When I removed it
let blob = new Blob([ics_string_from_indexedDB], { type: 'text/calendar' })
it started working.
本文标签: javascript in mobile safari (iOS) won39t download calendar inviteStack Overflow
版权声明:本文标题:javascript in mobile safari (iOS) won't download calendar invite - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745166638a2645722.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论