Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

data:uri for ical does not work on Android or iPhone

I'm attempting to create a calendar entry using ical on a mobile device using data:Uri as described in https://stackoverflow.com/a/4551467/90236. Now it works great on my desktop machine when I run this in Chrome and my calendar app is MS Outlook.

Basically, what I do in Javascript is:

var icalsample = "BEGIN:VCALENDAR\r\n\
VERSION:2.0\r\n\
PRODID:-\/\/mycompany.com\/myproduct\/\/NONSGML v1.0\/\/EN\r\n\
BEGIN:VEVENT\r\n\
UID:" + uuid + "@mycompany.com\r\n\
DTSTAMP:" + dtstamp.toISOString() + "\r\n\
ORGANIZER;CN=mycompany scheduler\r\n\
DTSTART:" + dtstart.toISOString() + "\r\n\
DTEND:" + dtend.toISOString() + "\r\n\
SUMMARY:" + title + "\r\n\
DESCRIPTION:" + description + "\r\n\
END:VEVENT\r\n\
END:VCALENDAR\r\n";

var uriContent = "data:text/calendar," + encodeURIComponent(icalsample);
location.href = uriContent;

An example uriContent from my app is below. When I copy and paste it into Chrome's address bar it works as expected:

data:text/calendar,BEGIN%3AVCALENDAR%0AVERSION%3A2.0%0APRODID%3A-%2F%2Fmycompany.com%2Fmyproduct%2F%2FNONSGML%20v1.0%2F%2FEN%0ABEGIN%3AVEVENT%0AUID%3A3e40a5db-bfe3-4ab5-92c0-22cb7aeaa2d4%40mycompany.com%0ADTSTAMP%3A2013-03-15T18%3A17%3A55.792Z%0AORGANIZER%3BCN%3Dmycompany%20scheduler%0ADTSTART%3A2013-03-18T16%3A00%3A00.000Z%0ADTEND%3A2013-03-18T20%3A00%3A00.000Z%0ASUMMARY%3AService%20Appointment%0ADESCRIPTION%3Aupgrade.%0AEND%3AVEVENT%0AEND%3AVCALENDAR

My problem is it does not work on iPhone or Android. From what I had read, I thought data:Uris were supported.

On Android 4.1.1 using the default browser (not Chrome), I see the text of my string displayed like a plain text document in the browser. On iPhone I see "Download Failed: Safari cannot download this file".

How can I make this work on iPhone and Android?

Update---

There some some errors in the original code above. All lines must end in \r\n. I had only \n. The last line also requires \r\n. The javascript Date.toISOString format is not valid for iCal. You have to remove the dashes, semicolons, and fractions of a second. A really valuable tool for catching these errors is the ical validator.

Most importantly, I don't think Android supports iCal or ics files. There are lots of forums posts discussing this and 3rd party tools to fill this gap. So I think my code was correct (apart from the bugs listed above in the update), but it failed on my phone because not app or Intent is registered for the text/calendar mime type.

like image 359
Michael Levy Avatar asked Mar 15 '13 18:03

Michael Levy


2 Answers

I had the same problem - and until I found this thread, I couldn't get the iPhone to read my iCal file.

Safari would say "Safari cannot download this file" which is misleading - Safari had downloaded the file - but it didn't like the standard ISO format date, with dashes and colons.

The solution, as you rightly put it is:

  • Make sure the line endings are CRLF.
  • Make sure there are no empty lines above BEGIN:VCALENDAR
  • Make sure the date format is ISO - but has dashes and semi-colons removed.

Thanks for pointing in the right direction!

like image 111
Ian Smedley Avatar answered Nov 08 '22 03:11

Ian Smedley


I tried this exact code and it worked!!!

BEGIN:VCALENDAR
PRODID:-//Some organization//some application//EN
VERSION:2.0
METHOD:REQUEST
BEGIN:VEVENT
UID:20120925T072912Z-140@http://localhost/www/
CREATED:20120925T072912Z
DTSTAMP:20120922T090500Z
DTSTART:20120922T090500Z
DTEND:20120923T090500Z
DESCRIPTION:Please attend this sample meeting
SUMMARY:Invitation to attend training
LOCATION:Earth
ATTENDEE;RSVP=TRUE:mailto:[email protected]
ORGANIZER;[email protected]:mailto:[email protected]
LAST-MODIFIED:20120922T090500Z
PRIORITY:5
SEQUENCE:0
STATUS:CONFIRMED
TRANSP:TRANSPARENT
END:VEVENT
END:VCALENDAR
like image 30
benjamingranados Avatar answered Nov 08 '22 03:11

benjamingranados