チンペイペイペイ☆

iOSアプリ、大阪のカレー、子育て、iPhoneL♡VE部なブログ

【iOS】EventKitを使って標準のリマインダーに投稿する


どうも、ちんぺい(@tinpay)です。

ちょっとEventKitをさわってたので、備忘録もかねてメモメモ。

#import <EventKit/EventKit.h>
#import <EventKitUI/EventKitUI.h>

EKEventStore *eventStore;
EKCalendar *eventCalendar;

eventStore = [[EKEventStore alloc] init];
[eventStore requestAccessToEntityType:EKEntityTypeReminder completion:^(BOOL granted, NSError *error) {
eventCalendar = [eventStore defaultCalendarForNewReminders];
}];

 

こんな感じでイベントストアに接続します。

で、上記の例では投稿するカレンダーにはリマインダー標準のものを設定してます。

 

で、投稿ロジック。

EKReminder *postReminder = [EKReminder reminderWithEventStore:eventStore];
postReminder.title = @”牛乳を買って帰る”;
postReminder.calendar = [eventStore defaultCalendarForNewReminders];
NSError *error;
BOOL success = [eventStore saveReminder:postReminder commit:YES error:&error];
if (!success) {
// 投稿失敗時
NSLog(@”%@”,[error description]);
}

これだけでリマインダーに投稿できちゃいます。

 

投稿先のカレンダーを変えたい場合は、

NSArray *calendars = [eventStore calendarsForEntityType:EKEntityTypeReminder];
for (EKCalendar *calendar in calendars) {
・・・
}

これで登録されているカレンダーが取得できるので、その中から投稿したいカレンダーを選んでください。

 

 

以上。

 

, , ,

2 thoughts on “【iOS】EventKitを使って標準のリマインダーに投稿する

【おはあぷ】テレビの影響力ってやっぱりスゴいね。 | あぷまがどっとねっと にコメントする コメントをキャンセル

メールアドレスが公開されることはありません。 * が付いている欄は必須項目です

次のHTML タグと属性が使えます: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>