I'm not sure why you get this behavior, but I think due to the fact that having disabled iCloud, the system cannot make queries on it and then queue creation requests that are resolved once you wake iCloud (but I'm assuming).
Anyway, the first solution that comes to my mind is to check if iCloud is active or not in this way
EKSource *defaultSource = [eventStore defaultCalendarForNewEvents].source;
if (defaultSource.sourceType == EKSourceTypeCalDAV)
NSLog(@"iCloud Enable");
else
NSLog(@"iCloud Disable");
this is done you can save your events to the default source properly and then keep the 2 calendars (the local one and the cloud one) synchronized with each other ...
Reactivation of iCloud will still be prompted to add all local calendars.
see also the second answer here Accessing programmatically created calendar on iOS device (which is where I got the idea ;) )
I hope I was helpful.
EDIT: Maybe is not necessary to create a second calendar... Try to change the source of the calendar from EKSourceTypeCalDAV to EKSourceTypeLocal ... don't forget to save calendar with commit "YES"
EDIT2: Ok just tested ...
substitute this:
} else { // Create Calendar
EKSource *theSource = nil;
for (EKSource* src in eventStore.sources) {
if ([src.title isEqualToString:@"iCloud"]) {
theSource = src;
break;
}
if (src.sourceType == EKSourceTypeLocal && theSource==nil) {
theSource = src;
break;
}
}
[self setupCalendarWithSource:theSource withEvent:event];
}
with this ...
} else { // Create Calendar
EKSource *theSource = [eventStore defaultCalendarForNewEvents].source;
[self setupCalendarWithSource:theSource withEvent:event];
}
this way u will create the calendar in the right source (local if user deactivate iCloud and CalDAV otherwise)
then:
1) when user choose to deactivate iCloud should leave calendars on iphone (and not delete) so u have the cloud calendar in the local source
2) when user choose to activate iCloud will merge his local calendars with the cloud and there u go!!
i hope this help
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…