保存時に取得する eventIdentifier は、eventIdentifier を使用してイベントを取得できません。
そのため、eventIdentifier がある場合でも、プログラムで EKEvent を更新することはできません。
Appleが提供する[SimpleEKDemo][1]では
EKEventEditViewDelegate メソッドで eventIdentifier をログに記録する
- (void)eventEditViewController:(EKEventEditViewController *)controller
didCompleteWithAction:(EKEventEditViewAction)action {
NSError *error = nil;
EKEvent *thisEvent = controller.event;
switch (action) {
case EKEventEditViewActionCanceled:
// Edit action canceled, do nothing.
break;
case EKEventEditViewActionSaved:
// When user hit "Done" button, save the newly created event to the event store,
// and reload table view.
// If the new event is being added to the default calendar, then update its
// eventsList.
if (self.defaultCalendar == thisEvent.calendar) {
[self.eventsList addObject:thisEvent];
}
[controller.eventStore saveEvent:controller.event span:EKSpanThisEvent error:&error];
NSLog(@"thisEvent.id = %@", thisEvent.eventIdentifier);
[self.tableView reloadData];
break;
case EKEventEditViewActionDeleted:
// When deleting an event, remove the event from the event store,
// and reload table view.
// If deleting an event from the currenly default calendar, then update its
// eventsList.
if (self.defaultCalendar == thisEvent.calendar) {
[self.eventsList removeObject:thisEvent];
}
[controller.eventStore removeEvent:thisEvent span:EKSpanThisEvent error:&error];
[self.tableView reloadData];
break;
default:
break;
}
// Dismiss the modal view controller
[controller dismissModalViewControllerAnimated:YES];
}
デバイスでアプリケーションを実行すると、次のような eventIDentifier が取得されます。
eventidonsave = 3CB60848-6CCA-43BF-B2C6-9EB9F5CFBBB7:C6CDE9DAA864420BA9A2E02CD8863697000000000000000000000000000000
次回の実行時にイベント識別子を使用してイベントを取得する
EKEventStore *eventStore1 = [[EKEventStore alloc] init];
EKEvent *event1 = [eventStore1 eventWithIdentifier: eventidonsave ];
if(event1){
NSLog(@"event1 id = %@", event1.eventIdentifier);
}else{
NSLog(@"Not Found");
}
「見つかりません」と表示されます。
フェッチ イベントの代わりにイベント ID をログに記録し、アプリを再度実行します。
- (NSArray *)fetchEventsForToday {
....
....
for(EKEvent *eachEvent in events){
NSLog(@"eachEvent.id = %@", eachEvent.eventIdentifier);
}
}
3CB60848-6CCA-43BF-B2C6-9EB9F5CFBBB7:040000008200E00074C5B7101A82E00000000000000000064646C6C6F747573C3C3C3C3000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000646464646464646464646464644C5B7101Aのような別のEventIdentifierを取得していることがわかります。
これは「eventidonsave」と同じではありません
こんにちは、読んでくれてありがとう。解決しました。上記のコード(編集されていない)は正常に機能しています。問題は、この行「[controller.eventStore saveEvent:..」の前にイベント ID がログに記録されたことだと思います。
いいえ、保存後に移動しました。で、大丈夫そうです。