在我的应用程序(Symfony2)中,我必须从 UI 向用户提供 .vcs 和 .ics 文件以添加到他们的设备日历中。我已经为 iPhone 完成了它,但我的 Android 解决方案不起作用。它一直在下载过程中,永远不会完成。
当我使用纯 PHP 执行相同的代码时,它可以工作并下载文件并集成到设备日历中。
普通 PHP 的代码:
<?php
header("Content-Type: text/x-vCalendar");
header("Content-Disposition: attachment; filename=calendar.vcs");
?>
BEGIN:VCALENDAR
PRODID:-//AT Content Types//AT Event//EN
VERSION:2.0
METHOD:PUBLISH
BEGIN:VEVENT
DTSTAMP:20120801T133822Z
CREATED:20120801T042948Z
LAST-MODIFIED:20120801T043003Z
SUMMARY:My Event
DTSTART:20130719T000000Z
DTEND:20130720T000000Z
LOCATION:London
URL:https://www.myurl.com/
CLASS:PUBLIC
END:VEVENT
END:VCALENDAR
Symfony2 的代码:
public function getCalendarAction()
{
//$filename = "calendar_".date("Y_m_d_His").".vcs";
$content = "BEGIN:VCALENDAR
PRODID:-//AT Content Types//AT Event//EN
VERSION:2.0
METHOD:PUBLISH
BEGIN:VEVENT
DTSTAMP:20120801T133822Z
CREATED:20120801T042948Z
LAST-MODIFIED:20120801T043003Z
SUMMARY:My Event
DTSTART:20130719T000000Z
DTEND:20130720T000000Z
LOCATION:London
URL:https://www.myurl.com/
CLASS:PUBLIC
END:VEVENT
END:VCALENDAR";
$headers = array('Content-Type' => 'text/x-vCalendar',
'cache-control'=>'no-store, no-cache, must-revalidate',
'Content-Disposition' => 'attachment; filename="calendar.vcs"');
return new Response($content, 200, $headers);
}
如果有人有解决问题的方法,请发布。