我正在尝试向iCloud EKSource添加日历,我正试图以这种方式找到iCloud日历:
EKSource *theSource = nil;
for (EKSource *source in eventStore.sources) {
if (source.sourceType == EKSourceTypeCalDAV && [source.title isEqualToString:@"iCloud"]) {
theSource = source;
break;
}
}
但是找不到我的任何EKSource,如何在icloud上添加日历,看看icloud中有多少个日历?
答案 0 :(得分:0)
也许这样的事情可以帮助你......
- (void)saveEventToiCloud {
EKEventStore *eventDB = [[EKEventStore alloc] init];
NSArray *calender = [[eventDB calendars] retain];
NSString * typeString = @"";
EKCalendar *iCloud;
for (EKCalendar *thisCalendar in calenders)
{
EKCalendarType type = thisCalendar.type;
if (type == EKCalendarTypeCalDAV)
{
NSString *calName=[NSString stringWithFormat:@"%@", thisCalendar.title];
NSRange range = [calName rangeOfString:@"iCloud"]; //Couldn't find better way, if there is, then tell me too. :)
if(range.length!=0)
{
//icloud
iCloud = thisCalendar;
break;
}
else
{
//any other email account
}
}
}
if(iCloud){
NSError *error = nil;
EKEvent *thisEvent = [[EKEvent eventWithEventStore:eventDB] retain];
thisEvent.title = @"Title";
thisEvent.startDate = [NSDate date];
thisEvent.endDate = [NSDate date];
thisEvent.calendar = iCloud ;
BOOL saved = [eventDB saveEvent:thisEvent span:EKSpanThisEvent error:&error];
NSLog(@"Saved calendar event = %@\n", (saved ? @"YES" : @"NO"));
[thisEvent release];
thisEvent=nil;
}
[events release];
[eventDB release];
}