8

我有一个为移动网络应用程序自动生成 ics 文件的 php 脚本。

在我的 Win7 桌面上使用 Chrome,ics 文件下载正常,并且 Outlook 喜欢它。

在我的 iPhone 上使用 Safari,ics 文件按预期打开日历应用程序,并允许我添加到日历。

在我的 iPhone 上使用 Chrome,我得到“下载失败。Chrome 无法下载此文件。错误 102 ():未知文件类型。”

我正在发送这些标头:

header("Content-Type: text/Calendar; charset=utf-8");
header("Content-Disposition: inline; filename={$slug}.ics");
header("HTTP/1.0 200 OK", true, 200);

我的 ics 文件输出是:

BEGIN:VCALENDAR
VERSION:2.0
CALSCALE:GREGORIAN
PRODID:-//example.com//NONSGML blah blah//EN
METHOD:PUBLISH
BEGIN:VEVENT
UID:20130412T062148-527420343@example.com
DTSTAMP:20130412T062148
DTSTART:20130524T134500Z
DTEND:20130524T153000Z
LOCATION:
SUMMARY:This is the summary
DESCRIPTION:This is the description
STATUS:CONFIRMED
TRANS:OPAQUE
END:VEVENT
END:VCALENDAR

关于 iPhone Chrome 不喜欢什么的任何想法?

4

3 回答 3

4

它看起来像 iOS 版 Chrome 中的一个错误。见https://bugs.chromium.org/p/chromium/issues/detail?id=666211

于 2017-08-22T09:45:35.217 回答
1

我看到的大多数例子都是小写的 http://www.w3.org/Protocols/rfc1341/4_Content-Type.html

试着做那个

内容类型:文本/日历

不是

内容类型:文本/日历

于 2013-05-11T11:52:46.300 回答
0

使用 webcal://your_link.ics

这应该可以解决您的问题。这是它的外观预览

这是一个jsbin,演示了基于用户代理的协议自动选择。

HTML:

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title>JS Bin</title>
</head>
<body>
  <a href="webcal://w3assets.angelbroking.com/wp-content/uploads/2020/07/ANGEL_BROKING_MONSOON_FESTIVAL.ics">Test webcal://</a>
  <br><br>
  <a href="https://w3assets.angelbroking.com/wp-content/uploads/2020/07/ANGEL_BROKING_MONSOON_FESTIVAL.ics">Test https://</a>
  <br><br>
  <a id="auto" href="https://w3assets.angelbroking.com/wp-content/uploads/2020/07/ANGEL_BROKING_MONSOON_FESTIVAL.ics">Auto (check JS)</a>
  <br><br>
  <textarea readonly id="ua"></textarea>
</body>
</html>

Javascript:

// Source: https://stackoverflow.com/a/9039885/3577736
function is_iOS() {
  return [
    'iPad Simulator',
    'iPhone Simulator',
    'iPod Simulator',
    'iPad',
    'iPhone',
    'iPod'
  ].includes(navigator.platform)
  // iPad on iOS 13 detection
  || (navigator.userAgent.includes("Mac") && "ontouchend" in document)
}

if(is_iOS()) {
    document.getElementById('auto').href = document.getElementById('auto').href.replace(/https?:/, 'webcal:');
}

// Debugging
document.getElementById('ua').value =  navigator.userAgent;

CSS:

textarea {
  width: 100%
}
于 2020-07-21T16:32:40.667 回答