我在Django中创建了服务端函数,它返回一个ICS文件:
path = os.path.join(ics_dir_path, ics_name)
if not os.path.exists(path):
return HttpResponseNotFound('<h1>ICS file not found</h1>')
try:
ics_content = file(path, "rb").read()
response = HttpResponse(ics_content, content_type="text/calendar; charset=ascii")
response['Content-Disposition'] = str.format('attachment; filename="{0}"', ics_name)
response['Accept-Ranges'] = 'bytes'
response['Content-Length'] = os.stat(path).st_size
except:
return HttpResponseServerError('<h1>Error in ICS file</h1>')
return response
ICS文件包含以下内容:
BEGIN:VCALENDAR
VERSION:2.0
BEGIN:VEVENT
SUMMARY:This is title
DTSTART;VALUE=DATE-TIME:20121010T020600
DTEND;VALUE=DATE-TIME:20121015T020900
DTSTAMP;VALUE=DATE-TIME:20121019T080543Z
END:VEVENT
END:VCALENDAR
我还创建了使用此URL获取ICS文件的iPhone应用程序。 出于某种原因,当我在我的iPhone应用程序中调用url时,它不会将事件添加到我的iPhone日历中。当我通过Mac的Safari调用url时,它会毫无问题地添加它。
我做错了什么?