I receive alot of emails regarding this module and the incompatibility with iOS 7, so I've started fixing the problems. Be patient with me :-)
Feb 8, 2013
- Added
Ti.Calendar.fetchEvents(object[startDate, endDate])
- Added
Ti.Calendar.fetchEvent(ids[identifier])
- Added
Ti.Calendar.deleteEvent(ids[identifier])
- Added QA page for various questions and answers
- Added
Ti.Calendar.hasCalendarAccess
Jan 9, 2013
- Fix for #23
Jan 2, 2013
- Added eventlistener "longpress"
- Added VoiceOver/Accessibility support
- Updated docs
Dec 16, 2012
- Added more details in the UITableView, including start date, end date and a subtitle using the events location)
- alarmOffset now returned to each event having an alarm set
For a more detailed changelog, check the Commit History
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)
-
[object] alarm: Event alarm (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
},
alarm: {
offset: -900 // 15 minutes before startDate
}
});
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);
Fetches an array containing events between dates. Useful if you dont want to use the Calendar View.
- [date] fromDate: From date (Javascript date object) (*)
- [date] toDate: To date (Javascript date object) (*)
* Optional. If no from or toDate is present, distantPast and distantFuture is used.
var from = new Date(); from.setDate(from.getDate()-1); var Events = Ti.Calendar.getEvents({ fromDate: from, toDate: new Date() });
for (var i=0;i<Events.length;i++) {
Ti.API.info(Events[i].title);
}
- [string] title
- [string] type (*)
- [string] note (*)
- [string] location
- [string] attendees (*)
- [string] description (*)
- [string] identifier (**)
- [string] organizer (*)
- [date] startDate (Standard dateTime format)
- [date] endDate (Standard dateTime format)
- [float] alarmOffset (Seconds) (EventKit only)
(*) 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.
Fetches details of a given event, based on the identifier.
var Event = Ti.Calendar.fetchEvent("baedff11f74a256bfbca4336e38c6483");
Ti.API.info(JSON.stringify(Event));
- [string] title
- [string] type (*)
- [string] note (*)
- [string] location
- [string] attendees (*)
- [string] description (*)
- [string] identifier (**)
- [string] organizer (*)
- [date] startDate (Standard dateTime format)
- [date] endDate (Standard dateTime format)
- [float] alarmOffset (Seconds) (EventKit only)
(*) 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.
Programmatically delete event by identifier.
Ti.Calendar.deleteEvent("baedff11f74a256bfbca4336e38c6483");
This can be used for the identifier-parameter in the createView()-instance.
- [string] MD5 sum of globallyUniqueString
Used to check whether the user has granted access to the built-in calendar(EventKit)
Added in version 1.2.8
- [boolean] true or false
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)
- [float] alarmOffset (Seconds) (EventKit only)
(*) 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);
});
Know which date/tile has been touched.
- [date] date (Standard dateTime format)
calendarView.addEventListener("date:clicked", function(e) {
var date_clicked = new Date(e.event.date);
Ti.API.info("Date clicked: "+monthNames[date_clicked.getMonth()]+" "+date_clicked.getDate() +".");
});
Fires whenever a datetile is pressed 0.5 seconds or more. Could be used to allow users to add events to the calendar by longpressing the day of month they want an event to be added.
Requested by Digitalico - Issue #22
- [date] date (Standard dateTime format)
calendarView.addEventListener("date:longpress", function(e) {
var date_clicked = new Date(e.event.date);
var dialog = Ti.UI.createAlertDialog({
message: "Would you like to add a new event on "+monthNames[date_clicked.getMonth()]+" "+date_clicked.getDate()+". ?",
buttonNames: ['Yeah!', 'Cancel'],
cancel: 1,
title: 'New event'
});
dialog.addEventListener('click', function(e){
Ti.API.info(e.index == 0 ? "Add event functionality..." : "No event added");
});
dialog.show();
});
Fires whenever the month is changed
- [date] date (Standard dateTime format) (*)
(*) Coming in 1.2.6. Currently not returning anything, just fires the event.
calendarView.addEventListener("month:next", function() {
Ti.API.info("Going to next month");
});
Fires whenever the month is changed
- [date] date (Standard dateTime format) (*)
(*) Coming in 1.2.6. Currently not returning anything, just fires the event.
calendarView.addEventListener("month:previous", function() {
Ti.API.info("Going back to previous month");
});
See example.
Chris Magnussen for Appgutta, DA.
Copyright(c) 2013 Appgutta, DA. Please see the LICENSE file included in the distribution for further details.
This module uses klazuka's calendar component.