0

在我的应用程序(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);    
}

在此处输入图像描述在此处输入图像描述

如果有人有解决问题的方法,请发布。

4

1 回答 1

0

问题现已解决。当我使用有效的受信任 SSL 证书在服务器上测试我的代码时,它会下载文件并集成到 Android 设备日历中。

于 2013-07-24T14:00:19.980 回答