I'm trying to create an event with one alarm programmatically like that:
+(void)exportEvent:(AgendaEvent*)evento
onCalendar:(EKCalendar*)calendar {
EKEventStore* store= [[[EKEventStore alloc] init] autorelease];
[store requestAccessToEntityType:EKEntityTypeEvent completion:^(BOOL granted, NSError *error) {
dispatch_async(dispatch_get_main_queue(), ^{
if(!granted) {
// show "not granted" message
return;
}
// save event
NSCalendar* gc= [[[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar] autorelease];
EKEvent* event= [EKEvent eventWithEventStore:store];
event.title= evento.descrizione;
event.startDate= [gc dateFromComponents:evento.begin];
if(evento.end)
event.endDate= [gc dateFromComponents:evento.end];
else {
NSDateComponents* endDateComponents= [[evento.begin copy] autorelease];
endDateComponents.day++;
endDateComponents.hour= 0;
endDateComponents.minute= -1;
endDateComponents.second= 0;
NSDate* endDate= [gc dateFromComponents:endDateComponents];
// endDate is correctly set at 23:59 of the same day of beginDate, when all day beginDay is at 00:00
event.endDate= endDate;
event.allDay= YES;
}
event.calendar= calendar;
// reminder
NSDateComponents* reminderDateComponents= [[evento.begin copy] autorelease];
reminderDateComponents.day--;
reminderDateComponents.hour= 9;
reminderDateComponents.minute= 0;
NSDate* reminderDate= [gc dateFromComponents:reminderDateComponents];
// reminder date is correctly set at 9:00 of the previous day of beginDate
[event addAlarm:[EKAlarm alarmWithAbsoluteDate:reminderDate]];
NSError* err= nil;
[store saveEvent:event span:EKSpanThisEvent commit:YES error:&err];
if(err) {
// show "unable to export" message
return;
}
// show "exported" message
});
}];
}
but some times only (or more correctly often) [store saveEvent:event span:EKSpanThisEvent commit:YES error:&err]
fails with:
2014-06-13 09:34:01.300 xxx[224:60b] CADObjectGetRelation failed with error Error Domain=NSMachErrorDomain Code=268435459 "The operation couldn’t be completed. (Mach error 268435459 - (ipc/send) invalid destination port)"
2014-06-13 09:34:01.301 xxx[224:60b] Impossibile esportare evento: Error Domain=EKErrorDomain Code=29 "Impossibile modificare avvisi." UserInfo=0x16a7c7e0 {NSLocalizedDescription=Impossibile modificare avvisi.}
I can't even find a description for code 29 in EKErrorDomain, does anybody have a clue?
Please mind that:
- I'm not using arc as you can see but seems pretty correct to me (an to static analyzer too).
- I've also tried to split the event save in two phases: one for the event and one for the alarm with exactly the same results.
- "Impossibile modificare avvisi." means "Can not change alerts."
- Tried on an iPad air with ios7.1.1 and ios7.1 simulator
CADObjectGetRelation
related message is not always shown even if event creation fails but seems to not appear when the event and alarms are created.