Corona SDK currently does not have direct access to the iOS “calendar” app, but you can still use your Corona-based app to add events to it. The process basically works like this:
- Collect input data from the user.
- Save an .ics file to your local file system.
- Upload that file to a web server.
- Use system.openURL() to access the file.
Collect Input Data
Getting input data from the user is fairly straightforward. First, decide on the User Interface (UI) you need and then collect the data. The type of data is defined in the standard ical format:
BEGIN:VCALENDAR VERSION:2.0 PRODID:-//hacksw/handcal//NONSGML v1.0//EN BEGIN:VEVENT UID:firstname.lastname@example.org DTSTAMP:20140517T190000Z ORGANIZER;CN=John Doe:MAILTO:email@example.com DTSTART:20140517T190000Z DTEND:20140517T195959Z SUMMARY:Corona Test Event LOCATION:Palo Alto, CA DESCRIPTION:This is my way cool event END:VEVENT END:VCALENDAR
You can learn more about the format here. Note that the key items you must provide are:
- UID — A unique ID for the event.
- DSTAMP — The date and time the event was created.
- DTSTART — The date and time the event starts.
- DTEND — The date and time the event ends.
- SUMMARY — The title of the event.
Save the File
Upload the File
Once the file is saved, you must upload it to a web server. The steps to upload a file and set up an upload script is beyond the scope of this tutorial, but if you’re new to the process, please see this tutorial.
Open the URL
When you’ve successfully completed the previous steps and you have a URL for the file, simply open that URL using system.openURL(). The operating system should recognize the .ics file and realize that you’re trying to set an event (you’ll be prompted to subscribe to the calendar and add the event). For example:
system.openURL( "http://yoursite.com/path/event.ics" )
Sample PHP Script
Forum member @alzaabi98 has shared a PHP script which can be used in place of uploading the file. This script and the sample code can be found here.
Hopefully this tutorial has shown you how to add basic events to the iOS calendar app. While this method does not offer any “advanced” calendar features, it provides you with a fairly simple way to input user-generated or other events.