iCloud calendar synchronization issue while creati

2019-04-12 05:40发布

问题:

Trying to implement iCloud Calendar synchronization for iOS. The idea is to create a new calendar from my app and sync it with iCloud when iCloud sync is on actually. To get corresponding source I'm using the following code:

EKSource* localSource=nil;

for (EKSource* source in self.eventStore.sources) { if(source.sourceType == EKSourceTypeCalDAV && [source.title isEqualToString:@"iCloud"]) { localSource = source; break; }

}

Then creating a calendar in that source and saving.

When iCloud sync is on and Calendar synchronization is on for iCloud as well from iPhone->Settings->iCloud->Calendar It's working just fine. After switching off calendar synchronization from above mentioned settings theoretically it should not allow to create calendar in that store any more. But actually even in that case it allows to get corresponding iCloud store from my application and create/save a new calendar. After creating a new calendar it's not showing it in iPhone's calendars list. But when you logging in to the iCloud web interface you can see there a lot of calendars with the same name that you have just added. The number of calendars with that name is getting more and more. Seams like there is an infinite loop problem in calendar synchronization for iCloud. So far seams like it's an iOS problem and could not find any report on that anywhere.

回答1:

Not sure if you figured this out, if you did, post your solution :-)

But it does seem to be a bug - I just checked iCal on my Mac and it's loaded up with duplicate calendars.

Just figuring it out, but some rough code I think I have working is to create a Calendar in the EKSource and then check for that Calendar.

Something like this:

-(BOOL)testCal {
  BOOL cal = 0;

  NSUInteger counter = 1;
  for (EKCalendar *thisCalendar in [[DGEK eventStore]calendars] ){
    NSLog(@"%@", thisCalendar.title);
    if ([thisCalendar.title isEqualToString:@"YourCalName"]) {
        cal = YES;
        return cal;
    }
    counter++;
  }
  return cal; 
}

I think that works. Just doing some more testing at the moment.

If the Cal doesnt exist I'm getting the default source with something like this:

source = [[[self eventStore] defaultCalendarForNewEvents] source];

Hope that helps.