リマインダーの繰り返しを自由に設定する (EventKit)

Post on 06-Jul-2015

2.005 views 7 download

description

Cocoa勉強会(関東) 64回 2014-02-08 EventKitを利用して、リマインダーアプリからは指定できない「繰り返し」を設定する。

Transcript of リマインダーの繰り返しを自由に設定する (EventKit)

"リマインダー"の繰り返しを自由に設定する

Cocoa勉強会#64/2014-02-08/木村渡

Powered by Rabbit 2.1.1 and COZMIXNG

リマインダー

http://support.apple.com/kb/HT4970?viewlocale=ja_JP

リマインダー

iOS/OS Xの標準アプリ

指定の期日にアラーム/通知

iCloudやiTunes経由で同期できる

これでタスク管理をしようとすると「むきー!」となるので注意

背景

iOS7になってからリマインダーを使いはじめた。

「3週間ごとの繰り返し」を設定したいモノができた。既定の繰り返しからしか選べない?

背景

EventKit

第55回の発表参照。

カレンダーとリマインダーへのアクセスを提供するフレームワーク。Calendar and Reminders Programming Guide (Mac Developer Library)邦訳カレンダーとリマインダーのプログラミングガイド

EKRecurrenceRule

EKRecurrenceFrequency

interval

Days of the Week

どうみても、いろんな繰り返しが指定できそう。

EKRecurrenceRule

ドキュメントを見た感じではさまざまな設定が可能。

実際に試して、確認する必要がある。

現在利用可能なもの以外の繰り返しの指定を受け入れるか。

リマインダーアプリがその繰り返しで動作するか。

EventKit超概要(リマインダー)

このような階層になっている。

EKEventStore - リマインダーor イベント

EKCalendar - "ビジネス"、"買い物"などの種類。

EKReminder - 個々のリマインダー

RubyCocoa+irbで試してみる

% irb1.8 -rosx/cocoa --simple-prompt>> include OSX>> require_framework 'EventKit'

※デモはirbでなくpryです。

ストアとカレンダーを取得

>> store = EKEventStore.alloc. initWithAccessToEntityTypes( EKEntityTypeReminder)>> calendars = store.calendarsForEntityType( EKEntityTypeReminder)>> calendar = calendars.find {|cal| cal.title == "テストだよ!"}

新規のリマインダーを作成

>> reminder = EKReminder. reminderWithEventStore(store)>> reminder.title = "3週間ごとに実⾏する!>> reminder.calendar = calendar

リマインダー期限を設定

>> due_date = NSDateComponents.alloc.init>> due_date.year = 2014; due_date.month = 2; due_date.day = 8>> due_date.hour = 18; due_date.minute = 30>> reminder.dueDateComponents = due_date

NSDateでいいじゃん…

3週間ごとの繰り返しを作成

>> rule = EKRecurrenceRule.alloc. initRecurrenceWithFrequency_interval_\ end(EKRecurrenceFrequencyWeekly, 3, nil)>> reminder.addRecurrenceRule(rule)

保存する

>> result, err = store.saveReminder_\ commit_error(reminder, true)=> [true, nil]

アプリで確認。

3週間ごとになっているかを確認

完了させて次の繰り返しへ。

3週間ごとになっているかを確認

もう一度。

3週間ごとになってる!

いろんな設定を試してみる

EKRecurrenceRuleの長ーいイニシャライザ。array渡す。

initRecurrenceWithFrequency: interval: daysOfTheWeek:daysOfTheMonth: monthsOfTheYear:weeksOfTheYear: daysOfTheYear: setPositions:end:

月2回(15日,月末)

frequency: EKRecurrenceFrequencyMonthly

daysOfTheMonth: [15, -1]

毎月第1、第3水曜日

frequency: EKRecurrenceFrequencyMonthly

daysOfTheWeek: EKRecurrenceDayOfWeek.dayOfWeek_weekNumber(4, 1),..

まとめとか感想とか

プログラムからはかなり自由に繰り返しを設定できる。

ただしアプリの表示は「カスタムの繰り返しパターン」に。

まとめとか感想とか

RubyCocoa便利ですよ!(宣伝)

10.5 Leopard以降のOS Xに標準インストール済み。

irb/pryで対話的に試行錯誤できる。コンパイル不要。

ruby 2.0や2.1への対応作業中…

Powered by Rabbit 2.1.1 and COZMIXNG