1

I have a Sencha Touch web application. I'm trying to generate a calendar event file and open it in another window hence forcing iOS to ask user to import this event into standard calendar.

I can do window.open and then use document.write to generate the file I want, but I also need to specify custom headers with content-type so Safari would recognize it as a calendar file.

Is it possible?

sha
  • 17,824
  • 5
  • 63
  • 98
  • Looks like this has been asked before - http://stackoverflow.com/questions/4325968/window-open-with-headers – mindparse Feb 23 '15 at 20:21
  • @mindparse: thank you. I saw that question. I'm not 100% married to window.open and wondering if may be other options are available. – sha Feb 23 '15 at 20:28

1 Answers1

1

If you redirect to or window.open a data URI, you can specify a MIME type.

As a simple test (Safari on iOS 6), I navigated manually to this data URI...

data:text/calendar;base64,QkVHSU46VkNBTEVOREFSDQpWRVJTSU9OOjIuMA0KUFJPRElEOi0vL2hhY2tzdy9oYW5kY2FsLy9OT05TR01MIHYxLjAvL0VODQpCRUdJTjpWRVZFTlQNClVJRDp1aWQxQGV4YW1wbGUuY29tDQpEVFNUQU1QOjE5OTcwNzE0VDE3MDAwMFoNCk9SR0FOSVpFUjtDTj1Kb2huIERvZTpNQUlMVE86am9obi5kb2VAZXhhbXBsZS5jb20NCkRUU1RBUlQ6MTk5NzA3MTRUMTcwMDAwWg0KRFRFTkQ6MTk5NzA3MTVUMDM1OTU5Wg0KU1VNTUFSWTpCYXN0aWxsZSBEYXkgUGFydHkNCkVORDpWRVZFTlQNCkVORDpWQ0FMRU5EQVI=

...and this pops up:

calendar popup

Casey Chu
  • 25,069
  • 10
  • 40
  • 59
  • This does work on a desktop (I'm getting `ics` file downloaded and if I open it on Mac it adds event to the Calendar app), but on iOS8 I'm getting an error message `This file cannot be downloaded`. Has the support for data URI was removed in latest iOS versions? – sha Mar 01 '15 at 16:07
  • 1
    Small correction. It did work on iOS too when I was accessing it from the browser directly. It gave me that error message when I was accessing web-app using home screen shortcut. I think the problem is with permission to contacts (since I was getting prompt to allow Safari to access contacts). I will investigate a bit more. Thank you. – sha Mar 01 '15 at 16:32