AGCalendar enables you to access the native calendar on your iPhone, iPad or iPod. EventKit and Core Data are both supported data sources. This enables you to switch between iCal and your custom calendar. Some more information below.
- EventKit: All events including the events in your native calendar will be shown. Events added will also be added to your native iCal.
- CoreData: Uses Core Data to store your calendar-events. Only events added by your application will be shown. Added events will not be added to iCal. This also allows you to add more details to your events.
To access this module from JavaScript, you would do the following:
Titanium.Calendar = Ti.Calendar = require("ag.calendar");
This will set the data source you want to use.
If this is not set, the calendar will default to EventKit as your data source.
Please read the description above for more information.
- [string] dataSource: eventkit or coredata (Default: eventkit)
Ti.Calendar.dataSource("coredata");
This will create a calendarView with controls to move back an forth between months.
- [boolean] editable: Turns "swipe-to-delete" on or off. Defaults to false
- [string] color: This is required by Titanium for some reason. Just set it to "white"
var calendarView = Ti.Calendar.createView({
top: 0,
editable: true,
color: "white"
});
This will add an event to your calendar object.
-
EventKit
-
[string] title: Event title
-
[string] location: Events location.
-
[string] note: Event notes.
-
[date] startDate: Events start. (Javascript date object)
-
[date] endDate: Events end. (Javascript date object)
-
[object] recurrence: Recurrence rule (EventKit only)
-
Core Data (Including the above)
-
[string] type: Event type. E.g: public or private
-
[string] attendees: Comma-separated list of attendees
-
[string] identifier: Event identifier.
-
[string] organizer: Name of the organizer
var endDate = new Date();
endDate.setHours(endDate.getHours()+3); // Set event to last 3 hours.
// Date to end our recurring event
var recurringEnd = new Date();
recurringEnd.setMonth(recurringEnd.getMonth()+6); // Recurring ends in 6 months
calendar.addEvent({
title: "Attend the 2011 WWDC conference",
startDate: new Date(),
endDate: endDate,
location: "San Francisco",
identifier: Ti.Calendar.identifier,
type:"public",
attendees: "Steve, Phil",
organizer: "Chris Magnussen",
note: "Be mad about not getting the iPhone 5",
recurrence: {
frequency: "month", // day, week, month, year
interval: 1,
end: recurringEnd
}
});
Select todays date in the calendarView.
Nothing more, nothing less..
var calendarView = Ti.Calendar.createView(); var todayButton = Ti.UI.createButton({title: "Today"});
todayButton.addEventListener("click", function() {
calendarView.selectTodaysDate();
});
window.setLeftNavButton(todayButton);
Programatically set active date.
var calendarView = Ti.Calendar.createView(); var dateButton = Ti.UI.createButton({title: "Set custom date"});
dateButton.addEventListener("click", function() {
var newDate = new Date();
// Add 3 days to current date
newDate.setDate(newDate.getDate()+3);
calendarView.selectDate(newDate);
});
window.setLeftNavButton(dateButton);
This can be used for the identifier-parameter in the createView()-instance.
- [string] MD5 sum of globallyUniqueString
When adding this to the calendar-view you will get all event-data in a single array whenever a user clicks the event-table.
- [string] title
- [string] type (*)
- [string] location
- [string] attendees (*)
- [string] description (*)
- [string] identifier (**)
- [string] organizer (*)
- [date] startDate (Standard dateTime format)
- [date] endDate (Standard dateTime format)
(*) Only available when using Core Data as the data source.
(**) When using Core Data your custom identifier is returned, else the auto generated eventIdentifier in EventKit is returned.
calendarView.addEventListener("event:clicked", function(e) {
var event = e.event;
var start_date = new Date(event.startDate);
alert(event.title+" will start "+start_date);
});
See example.
Chris Magnussen for Appgutta, DA.
Copyright(c) 2012 by Appgutta, DA. All Rights Reserved. Please see the LICENSE file included in the distribution for further details.