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
.icsfile 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:
SUMMARY:Corona Test Event
LOCATION:Palo Alto, CA
DESCRIPTION:This is my way cool event
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.