Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-19573] iOS: Expose Reminders API

GitHub Issuen/a
TypeNew Feature
PriorityLow
StatusOpen
ResolutionUnresolved
Affected Version/sn/a
Fix Version/sn/a
ComponentsiOS
Labelsreminders
ReporterHans Knöchel
AssigneeUnknown
Created2015-09-24T03:38:44.000+0000
Updated2018-02-28T19:55:44.000+0000

Description

Apple introduced the Reminders API in iOS 6, that uses the EventKit framework (the same as Ti.Calendar is using now). We could expose the following methods on a new Reminders module: const Reminders = require('ti.reminders'); - Reminders.requestAuthorization() - Reminders.getAllReminders(); - Reminders.getReminderById(); - Reminders.createReminder(); - Reminders.removeReminder(); *Apple docs:* https://developer.apple.com/library/ios/documentation/DataManagement/Conceptual/EventKitProgGuide/ReadingAndWritingReminders/ReadingAndWritingReminders.html *Example architecture:*
const Reminders = require('ti.reminders');

const dataStructure = [{
	title: "Request authorization",
	action: requestRemindersAuthorization
},{
	title: "Get all reminders",
	action: getAllReminders
},{
	title: "Get reminder by ID",
	action: getReminderById
},{
	title: "Create reminder",
	action: createReminder
},{
	title: "Remove reminder",
	action: removeReminder
}]

const win = Titanium.UI.createWindow({
	backgroundColor : '#fff',
	layout : 'vertical'
});

dataStructure.forEach((data) => {
	const btn = Ti.UI.createButton({
		top : 20,
		left: 20,
		right: 20,
		height : 60,
		backgroundColor : '#efefef',
		title : data.title
	});

	btn.addEventListener("click", data.action);
	win.add(btn);
});

function requestRemindersAuthorization() {
	Reminders.requestAuthorization(function(e) {
		Ti.API.warn(e);
	});
}

function getAllReminders() {
	const allReminders = Reminders.getAllReminders()
	Ti.API.warn(allReminders);
}

function getReminderById() {
	const reminder = Reminders.getReminderById(3);

	if (!reminder) {
		alert("No reminder found matching the ID=" + id + "!");
	} else {
		Ti.API.warn(reminder);
	}
}

function createReminder() {
	const mainCalendar = Ti.Calendar.getCalendarById(1);

	if (!mainCalendar) {
		alert("The associated calendar could not be found!");
		return;
	}

	const newReminder = TiReminders.createReminder({
		title: "My Reminder",
		calendar: mainCalendar,
		alarm: new Date(2015,09,24)
	});
	newReminder.save();
}

function removeReminder() {
	const success = Reminders.removeReminder(3);
	
        if (!success) {
		alert("The reminder could not be deleted!");
	} else {
		alert("The reminder was successfully deleted!");
	}
}

win.open();

Comments

  1. Hans Knöchel 2017-11-19

    Considering as a native module instead of a new namespace these days!

JSON Source